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
    That prints all yeses for me and a bunch of warnings (change == to eq, perhaps?).

      :) Thanks. Fixed.

      (== should have been eq)


      Dave