in reply to Change variable multiple times within a single string?
my $state = 'no'; my $string = 'A111B111A111B111'; while( $string =~ m/ (?<chunk> (?<condition>[AB]) (?<value>\d+) ) /gx ) { $state = $+{condition} eq 'A' ? 'yes' : 'no'; print "($+{chunk}) => State: ($state) => Value ($+{value})\n"; }
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Change variable multiple times within a single string?
by toolic (Bishop) on Apr 28, 2013 at 13:08 UTC | |
by davido (Cardinal) on Apr 28, 2013 at 13:45 UTC |