... you want to declare the variable in as narrow a scope as you can and still be able to access it where you need to.
++dvergin!
Of course, this assumes that the fragment presented was whittled down to some minimum amount needed to ask the question.
In other words, it's probably safe to presume that the if block would be followed by code which does something with the @entries array, such as return a reference to it or its contents, in which case perhaps something like this is more appropriate:
sub openFile {
my ($file1, $file2) = @_; # assume these are passed as parameters
my $fn = $file1 || $file2; # replaces the 'if' in original
open FH, $fn or die "$fn: $!";
my @entries = <FH>;
close FH;
# in list context, return the entire array, else (scalar context) a
+ref
return wantarray ? @entries : \@entries;
}
dmm
You can give a man a fish and feed him for a day ...
Or, you can teach him to fish and feed him for a lifetime
|