On Friday 04 April 2003 14:54, Bob Showalter wrote:
Wow! I've coding in Perl for almost three years now and I didn't this.
Anyhoo, Bob's advice was the what I used and it works now. I just moved the
regex evals into the if condition statements vs the way I was doing it.
Thanks for the assistance guys.
- Jim
| Jim wrote:
| > I've never encountered this before but I have to be doing something
| > wrong.
| >
| > snippet of code:
| >
| > ]$ perl -e '
| >
| > > $var = "Company Online (Company Systems) NETBLK-COM-5BLK
| > > (NET-24-256-0-0-1)"; $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
| > > print $1,"\n";
| > >
| > > $var = "NetBlock: NETBLK-10H-6BLK";
| > > $var =~ /sdddd\(.*?\) (.*?) \(.*?\)/;
| > > print $1,"\n";
| > > '
| >
| > NETBLK-COM-5BLK
| > NETBLK-COM-5BLK
| >
| >
| > Why isn't $1 getting updated with the next implicit match? It should
| > fail but its returning the first $1 match. I can't unset $1 because
| > it is a read-only variable. This doesn't even work if I change the
| > second $var to $var2 because of course $1 is the same the way through.
| >
| > VERY frustrating.
|
| This is the way the $1, $2, etc. variables work. They are only set if there
| is a successful match. Otherwise, they simply retain whatever previous
| value they had.
|
| You either need to test that the match worked:
|
| if (/(\w+)/) {
| # $1 is now set
| print $1;
| }
|
| Or, evaluate the match in list context:
|
| my ($word) = /(\w+)/; # $word will be undef if no match
--
- Jim
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]