Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Change variable multiple times within a single string?

by BillKSmith (Priest)
on Apr 27, 2013 at 15:56 UTC ( #1030980=note: print w/replies, xml ) Need Help??


in reply to Change variable multiple times within a single string?

If you only need the final state. This code returns 'yes' only if there is an 'A' in the string and there is no 'B' after it.
use warnings; use strict; my $string="A111B111A111B111"; my $yes_or_no= ($string =~ m/A[^B]*$/) ? 'yes' : 'no'; print "yes_or_no=$yes_or_no\n";
Update: The original description is not quite accurate. It should read "This code returns 'yes' only if there is at least one 'A' in the string and there is no 'B' after the final 'A'."
Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030980]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-12-05 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (72 votes). Check out past polls.