Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Change variable multiple times within a single string?

by BillKSmith (Chaplain)
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


Comment on Re: Change variable multiple times within a single string?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-10-30 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (207 votes), past polls