in reply to File::Slurp read_file error
Also, I'd be more inclined to remove newlines from file- and path-names with chomp while populating the array. This way you don't have to worry about accidentally removing characters you want to keep with substr. For instance (not sure if this is the way you're going about this), if I had a file produced by doing ls -AR directory_name > filelist in the shell I would put it into an array like so:
.. and I'd use File::Spec to assemble the pathnames so I didn't need to worry about concatenating pathnames and filenames and slashes and whether there was already a trailing slash in the direcory name, etc:use strict; use warnings; use autodie; my $file = shift @ARGV; open my $fh, '<', $file; my @files; while ( my $line = <$fh> ) { chomp $line; push @files, $line unless $line =~ /^\s*$/; }
use File::Spec; my $dirname; for my $name ( @files ) { if ( $name =~ s/:$// ) { # use trailing : to id dirname $dirname = $name; } else { my $fullpath = File::Spec->catfile( $dirname, $name ); # slurp or do whatever with file at $fullpath } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File::Slurp read_file error
by patt (Scribe) on Aug 12, 2010 at 16:01 UTC |