Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

why doesn't this flip-flop work?

by johnnywang (Priest)
on Jan 27, 2006 at 19:38 UTC ( [id://526064]=perlquestion: print w/replies, xml ) Need Help??

johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

I happen to need the flip-flop after reading Flipin good, or a total flop?. The following behavior puzzles me, why does the first version print "after"? Thanks.
my @data = <DATA>; print "Using lexical varible:\n"; foreach my $line (@data){ if($line =~ /begin/../end/){ print $line; } } print "\nNot using lexical varible:\n"; foreach (@data){ if(/begin/../end/){ print; } } __DATA__ before begin 1 2 3 end after __RESULT__ Using lexical varible: begin 1 2 3 end after Not using lexical varible: begin 1 2 3 end

Replies are listed 'Best First'.
Re: why doesn't this flip-flop work?
by japhy (Canon) on Jan 27, 2006 at 19:42 UTC
    Your first code is ($line =~ /abc/) .. /xyz/. You mean to write ($line =~ /abc/) .. ($line =~ /xyz/). Case closed.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: why doesn't this flip-flop work?
by Roy Johnson (Monsignor) on Jan 27, 2006 at 19:42 UTC
    use warnings; will give you a clue.

    How do you think your first conditional parses?


    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-19 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found