in reply to Subroutines....return directory file is in and return contents in array
See module File::Basename to extract the directory name (dirname()) from the path, you already have. See module Cwd to get current working directory - if required.sub contents { open (FH, "< $FileInfoName") or die "Can't open $FileInfoName for re +ad: $!"; my @lines = <FH>; # return @lines; # 1st problem: in scalar context, number of lines is + returned # 2nd problem: next line is never reached close FH or die "Cannot close $FileInfoName: $!"; return join("", @lines); # fix: one big string with all lines concate +nated # See also File::Slurp }
Update: oops - you wanted contents() to return an array (Perl: list) -- then you can keep the return @lines; (in last line) and change the callers context as toolic suggested.
Maybe two other suggestions?
|
|---|