in reply to Re: Local variables assigned to pattern matches
in thread Local variables assigned to pattern matches

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).

  • Comment on Re: Re: Local variables assigned to pattern matches

Replies are listed 'Best First'.
Re: Re: Re: Local variables assigned to pattern matches
by japhy (Canon) on Mar 30, 2001 at 11:28 UTC
    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