in reply to Passing globals and magic variables safely

I avoid the $<DIGITS> issue by hardly ever using them, and when I do use them I only use them at right hand side of an assignment and immediately after the match. I.e. I do my ($foo, $bar) = $baz =~ /.../ and $baz =~ /.../; my ($foo, $bar) = ($1, $2);.

ihb

See perltoc if you don't know which perldoc to read!

Replies are listed 'Best First'.
Re^2: Passing globals and magic variables safely
by ysth (Canon) on Apr 10, 2005 at 22:41 UTC
    Me too. In production code, I almost never use the regex variables except in a s///. Note that it is pretty easy to combine this with checking for successful match:
    my ($foo, $bar); unless (($foo, $bar) = $data =~ $pattern) { die "horribly!"; } ...

      I usually just go

      my ($foo, $bar) = $data =~ /$pattern/ or die "horribly!";

      ihb

      See perltoc if you don't know which perldoc to read!