Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Reading in Text File and skipping lines

by DamnDirtyApe (Curate)
on Nov 07, 2002 at 22:15 UTC ( [id://211269]=note: print w/replies, xml ) Need Help??


in reply to Reading in Text File and skipping lines

I prefer a different approach when reading a filehandle into a scalar.

my $outputpage; do { local $/; $outputpage = <TEMPLATE>; } ;

If you've not seen this before, it essentially says, "forget about what you thought an end-of-line character was, and read the whole thing." It only "forgets" for the scope of the do block, so the effect is totally isolated.


_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Replies are listed 'Best First'.
Re: Re: Reading in Text File and skipping lines
by dingus (Friar) on Nov 08, 2002 at 06:55 UTC
    If you just want to slurp a file into a scalar then this is a pretty simple way to do it, no need to worry about do's, while loops undefs etc.
    my $outputpage = join('',<TEMPLATE>) ;

    Dingus


    Enter any 47-digit prime number to continue.

      True. But you do have to worry about opening the file, checking the return code, outputing a sensible error message if it fails.

      The nice thing about juerd's slurp idiom (as shown in wonko the sane's post above) is that it takes care of that for you.


      Nah! You're thinking of Simon Templar, originally played (on UKTV) by Roger Moore and later by Ian Ogilvy

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found