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 ( #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? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-24 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?