Simple slurping

 | Perl | 0 Comments | 0 TrackBacks

This is more than likely the best way to read an entire file into a given variable $code all in one go:

my $code = do { local $/; <$fh> };

Notice that by localizing the input record separator $/ variable within the brackets, unwanted side-effects are avoided.

Of course, if one is more prone to power slurping, then the module Perl6::Slurp offers a much more advanced interface, but one will just have to be patient and wait awhile.

No TrackBacks

TrackBack URL: http://www.kiffingish.com/cgi-bin/mt/mt-tb.cgi/11

Leave a comment

Recent Entries

A walk along the Keizersgracht
Too often one is so consumed by a jungle of intertwined thoughts that the beauty of the nearby surroundings ... »
Popularity is fickle
The popularity of a given next generation technology is very fickle, and its success or failure depends on many ... »
Where was Kiffin really buried?
Hi There seems to be some confusion on the current resting place of Kiffin Rockwell, some say that his ... »
Going to Portugal
Normally the week just before I leave for summer vacation, I spend hours on end desperately searching for some ... »
A human language
These days it is not very often that a new and exciting Perl book comes along. That's why I ... »