Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030981]
help
Chatterbox?
[LanX]: there was a guy who tried to steal the concept and build an own monastery ...
[LanX]: yeah PM is very emacsy ;-)
[LanX]: I think tobyink was on a good track with his redesign, pitty the pmdevs/gods didn't try to continue the approach of a modern responsive design
[holli]: *sigh* why has there to be drama in such a thread?
[LanX]: ?
[holli]: Re^2: Let's Make PerlMonks Great Again! -- suggestions and dreams - STFU and write code already (start already)

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-11-20 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (292 votes). Check out past polls.

    Notices?