if ($bib =~ m{(,\s*?eds{0,1}(\s¦\.¦<))}isg)
{
print STDERR "$1";
}
prints every occurrence of the strings I want to kill, but
if ($bib =~ s{(,\s*?eds{0,1}(\s¦\.¦<))}{}isg)
{
print STDERR "$1";
}
gives me a warning about using an uninitialized variable in a concatenation on the line with the regexp. (NOT the line with the print statement. I've even tried deleting the print statement to be sure.)
and
$bib =~ s{(,\s*?eds{0,1}(\s¦\.¦<))}{}isg;
What am I missing to make sense of this?
Hope I understood the problem properly...I dont know why you get that error message, I never tried that construction. Frankly I don't understand why you want to use the substitution function if you replace the match by nothing anyway..
I suggest, if a match..print the match..else print the original $bib..
if ($bib =~ m{(,\s*?eds{0,1}(\s¦\.¦< ))}isg)
{ print STDERR "$1"; }
else {print STDERR "$bib"; }
Alternatively...maybe you could write something like
$bib =~ s{(,\s*?eds{0,1}(\s¦\.¦< ))}{}isg;
if ($1) {print "$1";}
else {print "$bib";}
undef $1;
Frankly I don't understand why you want to use the substitution function if you replace the match by nothing anyway.
$bib comes in in one format, and needs to leave my script looking rather different. I'm not ready to print $bib, and my only use for the text that matches my expression is that I want it to go away, while keeping everything before it and after it. s{expresions_i_don't_want}{}isg seems nicer than
while ($bib =~ m{(.*?)expression_i_don't_want(.*)}is)
{
$bib = $1 . $2;
}
In this case, the only reason I want to branch on it is so that I can print diagnostics while I'm working on the script. Since not trying to branch on it works just fine, for this script, I don't really *need* an answer, but I want to know why it happens the way it does.
I believe you can only use it on the right hand side of the s///g and then it goes out of scope.
Wrong.
"The numbered variables ($1, $2, $3, etc.) and the related punctuation set (<$+, $&, $`, and $') are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first."
perlre - Perl regular expressions [perldoc.com]
Andreas