Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to extract Start .. End from multiline file

by halley (Prior)
on Sep 28, 2005 at 17:56 UTC ( [id://495849]=note: print w/replies, xml ) Need Help??


in reply to How to extract Start .. End from multiline file

Two things of note. The two lines of code below are identical, thanks to magic in the perl parser.
while (<fh>) { ... } while (defined ($_ = <fh>)) { ... }
Your code, shown below, does not work the same way. {update: proven wrong below, but I still wouldn't use it}
while ($var = <fh>) { ... }
Also, the .. operator can't be used in the way you're working on your latter example. It needs to go between two complete expressions that will be evaluated for the range flipflop. You wrote:
if ($line =~ m/$stag/ .. /$etag/)
You meant:
if (($line =~ m/$stag/) .. ($line =~ m/$etag/))
Perl thought you meant:
if (($line =~ m/$stag/) .. ($_ =~ m/$etag/))
See it? You never assigned to $_ so it never got the end condition.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: How to extract Start .. End from multiline file
by revdiablo (Prior) on Sep 28, 2005 at 18:00 UTC
    Your code, shown below, does not work the same way.

    This is a common myth. I (pretty recently) used to believe the same thing. Deparse shows us the light, though:

    $ perl -MO=Deparse -e 'while ($var = <fh>) {}' while (defined($var = <fh>)) { (); }
Re^2: How to extract Start .. End from multiline file
by ikegami (Patriarch) on Sep 28, 2005 at 18:19 UTC
    Your code, shown below, does not work the same way.

    Are you sure?

    >perl -MO=Deparse -e "while ($var = <fh>) { }" while (defined($var = <fh>)) { (); } -e syntax OK
Re: How to extract Start .. End from multiline file
by gasho (Beadle) on Sep 28, 2005 at 18:46 UTC
    Thanks Ed for quick response Line:
    if (($line =~ m/$stag/) .. ($line =~ m/$etag/))
    did work fine :)

Log In?
Username:
Password:

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

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

    No recent polls found