in reply to where to declare a variable...
I would write that something like this:
More accurate name. Better error reporting. Less code duplication...use Carp; # Time passes... # takes a filename, and returns the contents of # the file as an array in array context, string in scalar. sub read_file { my $file = shift; local *IN; open(IN, "< $file") or confess("Cannot read '$file': $!"); return wantarray ? <IN> : join '', <IN>; }
|
---|