Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: slurp mode

by Spidy (Chaplain)
on Nov 01, 2005 at 17:17 UTC ( [id://504659]=note: print w/replies, xml ) Need Help??


in reply to slurp mode

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: slurp mode
by tinita (Parson) on Nov 01, 2005 at 18:18 UTC
    Generally when I'm reading in a file, I'll do something like this: open(FILENAME,">>filename.file");
    this opens the file for writing (appending), not for reading.

    for slurping i usually do

    my $content = do { local $/; <$fh> }; # or even my $content = do { open my $fh, '<', $file or die $!; local $/; <$fh> +};
Re^2: slurp mode
by sauoq (Abbot) on Nov 01, 2005 at 19:02 UTC

    As tinita said, you are appending. But, even if you corrected that, your while loop isn't so much slurping as sipping. Or something. You are losing most of the benefits of slurping and paying to do so with a number of unnecessary concatenations equal to the number of lines in your data. Just avoid all that rigamarole and use one of the methods presented here. (I.e. set $/ to undef either explicitly or by localizing it to a block.) It'll be one less reason for maintenance programmers to curse you.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-26 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found