in reply to Loosing variable content after regular expression
There's nothing wrong with the piece of code you have provided (except that it does nothing and does not even compile because it's incomplete). To get an answer, you should have tried to obtain a minimal reproducting exemple, which would probably have shown you what was wrong in the process.
The issue probably comes from where you get your reference, if you have $ref = \SOMETHING where SOMETHING comes from a regex (the most obvious case being $ref = \$1;, running another match may change the value your reference points to. For exemple, the following code has a issue similar to yours, except it fails at the first run:
my $l_Name_ref; for (qw/HELLO PERL MONKS/) { /(.+)/; $l_Name_ref = \$1; if (defined($$l_Name_ref)) { print STDERR "1 $$l_Name_ref\n" if (defined($$l_Name_ref)); print STDERR "2 $l_Name_ref\n"; if ($$l_Name_ref =~ /^[a-zA-Z]\w+$/) { print STDERR "3 $l_Name_ref\n"; print STDERR "4 $$l_Name_ref\n"; } } }
Edit: I changed my example, in the previous version I used @ARGV and shifted from it because of my first attempt at reproducing the defect but it did not make much sense in this last version.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Loosing variable content after regular expression
by metty (Initiate) on Dec 19, 2014 at 08:27 UTC |