in reply to Does redo create a new dynamic scope?
The $& is not set on the redone block. Look at perlre
The numbered match variables ($1, $2, $3, etc.) and the related punctuation set ($+ , $& , $` , $' , and $^N ) are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first.This block should give the behavior you were expecting, by storing the $& from the previous run.
#!/usr/bin/perl use strict; use warnings; my $b; for( $_ = "fred"; s/(.)//; ) { $b = $& if $&; print "I saw the character [$b]\n"; redo if $b eq 'e'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Does redo create a new dynamic scope?
by ikegami (Patriarch) on Jul 18, 2007 at 21:17 UTC | |
|
Re^2: Does redo create a new dynamic scope?
by TGI (Parson) on Jul 18, 2007 at 21:07 UTC | |
|
Re^2: Does redo create a new dynamic scope?
by Anno (Deacon) on Jul 18, 2007 at 21:04 UTC |