If I try to match a regular expression that contains parentheses, and the match fails, shouldn't $1 be set to undef rather than keeping whatever value it had before? The following program demonstrates what looks to me like very strange behavior. Adding "local $1 = undef;" in the position shown did not change this behavior.

-------------------
#!/usr/bin/perl -w

use strict;

sub1("There are 100 words.");

sub sub1 {
  my $s = shift;
  $s =~ /There are (\d+) words./;
  print "sub1 (before call): \$1=$1\n";
  sub2($s);
  print "sub1 (after call): \$1=$1\n";
}

sub sub2 {
  my $s = shift;
  # local $1 = undef;  <--- Adding this has no apparent effect.
  print "sub2 (before match): \$1=$1\n";
  $s =~ /There are ([a-z]+) words./;
  print "sub2 (after match): \$1=$1\n";
  }


------------------ The output:

sub1 (before call): $1=100
sub2 (before match): $1=100
sub2 (after match): $1=100
sub1 (after call): $1=100

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to