I assumed that, $1 would be reset (either undefined or set to null) once
I exited the scope of the while loop my regexp was called in. Sadly, I
was mistaken. :) Below is a test example of code I wrote, with $1 values
differing from those I expected. Do I need to explicitly set $1..$n to
an empty string before every regexp if I'm to test based on the results
of that regexp?

Thanks!
- Ed

-=-=-=-=-=-
#!/usr/bin/perl -w
use strict;
use warnings;

while (<DATA>) {
        chomp;
        /(\d+)/;
        print "\$1: $1\n";
}
__DATA__
1
2
a
3


Expected results:
$1: 1
$1: 2
$1:                     # <--- was expecting an empty string
$1: 3

Actual results:
$1: 1
$1: 2
$1: 2                   # <--- value of $1 never reset from the last run
$1: 3

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to