Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

why doesn't this flip-flop work?

by johnnywang (Priest)
on Jan 27, 2006 at 19:38 UTC ( #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

Comment on why doesn't this flip-flop work?
Download Code
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.
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

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-08-20 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (107 votes), past polls