One way to slurp
From JmPm
(Difference between revisions)
(from old wiki) |
m (Protected "One way to slurp": spam [edit=autoconfirmed:move=autoconfirmed]) |
Revision as of 12:40, 14 March 2007
Slurp means to read a whole file into a variable:
open( my $fh, $filename ) or die "cannot open file $filename $!\n"; my $text = do { local( $/ ) ; <$fh> } ;
this snippet of code shows how you can locally undef the variable $/ which contains the newline character. This pulls the whole file into $text and then automatically goes back to its original value when out of the block.