in reply to slurping into scalars

although rob_au and thinker have provided valid responses, i prefer to use a subroutine and stick it in a utility module. besides providing reusability, it does not pollute your namespace with filehandle names. here's a sample from my Utl module:

package Utl; require 5.006_001; use strict; use warnings; ## a library of categorized utilities and functions our $VERSION = 0.03; our %slurp = ( ## slurp a file to a scalar ## pass filename (as scalar) ## returns contents of file (scalar context) to_scalar => sub{ local( *ARGV, $/ ); @ARGV = @_; <> }, ## slurp one or more files to an array ## pass filename(s) (as scalar) ## returns contents of file(s) (list context) ## returns number of lines (scalar context) to_array => sub{ local *ARGV; @ARGV = @_; <> }, ); ### more utilities follow...

you'd use it like so:

my $file = $Utl::slurp{to_scalar}->( $filename ); ## or for an array... my @file = $Utl::slurp{to_array}->( $filename );

use it in good health.

~Particle *accelerates*