nysus has asked for the wisdom of the Perl Monks concerning the following question:
$x = $y =~ /^(z*)/;
local($x) = $y =~ /^(z*)/;
Two questions: How does this work? I know local variables carry over between subroutines, but why is it affecting the behavior of this one line?
My second question is more of a Perl philosophy question. The above bit of code strikes me as a bit unorthodox. It seems that backreferences should be used since they were designed for this very kind of situation. Now, as a new Perl programmer, I know "there is more than one way to do it", but are there times one should strive for the more correct way of doing things?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Local variables assigned to pattern matches
by japhy (Canon) on Mar 30, 2001 at 10:32 UTC | |
by nysus (Parson) on Mar 30, 2001 at 10:37 UTC | |
by japhy (Canon) on Mar 30, 2001 at 11:28 UTC | |
|
(bwana147) Local variables assigned to pattern matches
by bwana147 (Pilgrim) on Mar 30, 2001 at 19:08 UTC | |
|
Re (tilly) 1: Local variables assigned to pattern matches
by tilly (Archbishop) on Mar 31, 2001 at 00:40 UTC |