On Friday 04 April 2003 14:34, John W. Krahn wrote:
| Jim wrote:
| > I've never encountered this before but I have to be doing something
| > wrong.
|
| Yes, you are. This is the documented behaviour of the numeric variables
| and is why we always tell beginners to use them only if the regular
| expression matched.
Ok. I didn't put tests in my example code. However, I do have tests in my
actual code which is what led me to this whole fiasco. In this code I am
finding that the first test ($back) pasts...and rightly so. It should.
However, in the following regex ($line) it should fail sometimes...but it
doesn't. It doesn't because when $back returns $1 as a valid return from the
regex then $1 remains a valid rval for the condition for $line. I need to
get around that!
Here is my code:
76 for $back ( @data )
77 {
78 $go_on = 1;
79
80 # start infinite loop
81
82 while ( $go_on )
83 {
84
85 # if we see that there is a net_blk
86
87 $back =~ /.*\(.*\) (.*?) .*/;
88
89 if ( $1 )
90 {
91
92 # add it to the array
93
94 push(@ret,$1);
95
96 # walk it
97 push(@done,$1);
98 my @more = get_whois($1);
99
100 # repeat process
101 for my $line ( @more )
102 {
103 $line =~ /.* \(.*\) (.*?) .*/;
104
105 if ( $1 )
106 {
107 print "Pushing net_blk: $1\n";
108 push(@ret,$1);
109 }
110 else
111 {
112 print "Go on to next iteration.\n";
113 $go_on = 0;
114 }
115
116 print "Pushing $1 to [EMAIL PROTECTED] stack\n";
117 last if ( grep($1,@done) );
118 }
119 }
120 else
121 {
122 $go_on = 0;
123 }
124 }
125 }
|
| > snippet of code:
| >
| > ]$ perl -e '
| >
| > > $var = "Company Online (Company Systems) NETBLK-COM-5BLK
| >
| > (NET-24-256-0-0-1)";
| >
| > > $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
| > > print $1,"\n";
|
| print "$1\n" if $var =~ /.*? \(.*\) (.*?) \(.*?\)/;
|
| > > $var = "NetBlock: NETBLK-10H-6BLK";
| > > $var =~ /sdddd\(.*?\) (.*?) \(.*?\)/;
| > > print $1,"\n";
|
| print "$1\n" if $var =~ /sdddd\(.*?\) (.*?) \(.*?\)/;
|
| > > '
| >
| > 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.
|
| $1, $2, $3, etc. are only set on a successful match otherwise they
| retain the value from the previous successful match.
|
|
| John
--
- Jim
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]