Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

RE: Return the contents of a file

by chromatic (Archbishop)
on Apr 12, 2000 at 18:43 UTC ( [id://7383]=note: print w/replies, xml ) Need Help??


in reply to Return the contents of a file

You can also redefine the input record separator $/ to a null string:
local $/; my $scalar = <FH>;
That obviates the need for a while loop. Normally, $/ is set to a newline. That's why the magic <FILEHANDLE> reads one line at a time. Using a local $/ will change that to whatever separator you want. Specify none, slurp the whole thing. That could make your first example even more compact.

Log In?
Username:
Password:

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

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

    No recent polls found