One way to slurp

From JmPm

(Difference between revisions)
Jump to: navigation, search
Amire80 (Talk | contribs)
(from old wiki)
Newer edit →

Revision as of 12:17, 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.

Personal tools