Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Change variable multiple times within a single string?

by davido (Archbishop)
on Apr 27, 2013 at 16:09 UTC ( #1030981=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Change variable multiple times within a single string?
Download Code
Re^2: Change variable multiple times within a single string?
by toolic (Chancellor) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030981]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-11-22 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (124 votes), past polls