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

Re: How else can I read from a file without using a while loop, testing for the EOF?

by S@nto (Initiate)
on Apr 23, 2006 at 17:53 UTC ( [id://545140]=note: print w/replies, xml ) Need Help??


in reply to How else can I read from a file without using a while loop, testing for the EOF?

Much less dangerous than undef-ing $/ globably (and maybe forgetting to set it back) local-ize it to a block that just does your file reading:
my $string = do{ local $/; <$filehandle> };
Or you can use $RS if you can't (or don't want to) remember $/.

Replies are listed 'Best First'.
Re: Answer: How else can I read from a file without using a while loop, testing for the EOF?
by jdhedden (Deacon) on Apr 24, 2006 at 12:52 UTC
    I like the slurp method provided by IO::All:
    use IO::All; my @lines = io('file.txt')->slurp;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-23 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found