Thanks for getting back. Yeah, I just figured out it was the parentheses, not local (which I understand is not as good as passing references through @_.
What about the second part of the question (which obviously doesn't apply to this particular situation now). | [reply] |
The backreferences ($1, $2, ...) only last as to the end of the current scope, or to the next successful regex. Thus, it's pretty useful to keep them in another variable. Also, those variables are read-only, so if you need to extract something and modify it, you need another variable:
while (<>) {
chomp;
my ($name) = /(\w+\s+\w+)/;
$name =~ tr/\n\r\t\f / /s; # squish spaces
push @names, $name;
}
japhy --
Perl and Regex Hacker | [reply] [d/l] |