Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Beautiful .. operator

by Sandy (Curate)
on Oct 28, 2008 at 22:34 UTC ( [id://720123]=note: print w/replies, xml ) Need Help??


in reply to Beautiful .. operator

No, it still doesn't do what you advertise:

#!/usr/bin/perl use strict; use warnings; our $data; print "\n\n original\n"; foreach (split("\n",$data)) { if(/start/ .. (!(/start/../end/) && /end/)) { print "$_\n"} } print "\n\n analysis:\n"; print " - note that range operator is set to true when \$flag1 is t +rue\n"; print " becomes false only after \$flag3 has been set to tru +e\n"; print "\n"; foreach (split("\n",$data)) { my $flag1=0;my $flag2 = 0;my $flag3=0; $flag1 = 1 if (/start/); $flag2 = 1 if (/start/../end/); $flag3 = 1 if (!$flag2 && /end/); print "$flag1, $flag2, $flag3, $_",' 'x(15-length($_)); if(/start/ .. (!(/start/../end/) && /end/)) { print "success\n"} else {print "\n";} } BEGIN { our $data = << 'TEST'; a a a start b start c d e end f start g h i end j end k k l TEST }

result

original start b start c d e end f start g h i end j end analysis: - note that range operator is set to true when $flag1 is true becomes false only after $flag3 has been set to true 0, 0, 0, a 0, 0, 0, a 0, 0, 0, a 1, 1, 0, start success 0, 1, 0, b success 1, 1, 0, start success 0, 1, 0, c success 0, 1, 0, d success 0, 1, 0, e success 0, 1, 0, end success 0, 0, 0, f success 1, 1, 0, start success 0, 1, 0, g success 0, 1, 0, h success 0, 1, 0, i success 0, 1, 0, end success 0, 0, 0, j success 0, 0, 1, end success 0, 0, 0, k 0, 0, 0, k 0, 0, 0, l

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found