in reply to •Re: Regex Capturing: Is this a bug or a feature?
in thread Regex Capturing: Is this a bug or a feature?

Avoiding the problem is fine now that I know about it.
Normally I do say if ( m/(whatever)/ ){ assign} which is why I never noticed this before. But I've never heard anyone or read anything that equates dynamic scoping with anything other than local() in perl and I've seen the terms local and dynamic used interchangeably.

In my example (or at least the code it was reduced from) I did a match, saved the value and checked later for a defined value. If this was a "regular" dynamic scoped variable than I would be testing if it passed or failed, just later on.

I own and have read all the ORA Perl books (with the exception of Mastering Regular Expressions) and I don't recall it every being mentioned. I think it should be clarified in perlre is all.

-Lee

"To be civilized is to deny one's nature."
  • Comment on Re: •Re: Regex Capturing: Is this a bug or a feature?

Replies are listed 'Best First'.
Re(3): Regex Capturing: Is this a bug or a feature?
by Dog and Pony (Priest) on Sep 30, 2002 at 09:25 UTC
    It has bitten me too, and I bet some other people too. I know about it know, and it is ok, but what really lacks is documentation about it.

    I seem to recall that it triggers some awkvardness in solutions too, at times, as just because a regexp matches, it may not actually fill all of the $n variables, and old values may still be there, and that makes checking harder. I would have to get back on that with a real example though, in case it is my memory that fools me. :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
      I believe you're correct. I tried to verify my recollection and came up with something even stranger.
      #!/usr/bin/perl # 5.6.1 use strict; use warnings; my @values = qw ( one var.1 test); getsymbolval(@values); ################################################# sub getsymbolval{ my @syms = @_; foreach my $symbol (@syms){ $symbol=~m/(\w+)(\.)?(\d+)/; print "symbol: $symbol\t\$1: $1\t\$2:$2\n"; my ($ts,$te) = ($1,$2); } wantarray ? @syms : $syms[0]; } __END__

      Output follows (minus uninitilized warnings): What's up with just 'v' being in the regex?
      symbol: one $1: $2:
      symbol: var.1 $1: var $2:.
      symbol: test $1: v $2:
      Very odd.

      -Lee

      "To be civilized is to deny one's nature."