Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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?
NodeReaper gets the Vote Fairy drunk

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-06-22 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (525 votes). Check out past polls.