One way to slurp

From JmPm

Jump to: navigation, search

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