patt has asked for the wisdom of the Perl Monks concerning the following question:
The substr calls are necessary because when ls -AR returns its list of files and directories it will return directory names with a semi-colon and newline appended and file names are returned with a newline appended. These have to be removed also the directory name and file name have to be spliced with a / to give the read_file call a valid 'path/filename'. I assumed that read_file would read any file into a scalar, and I expected it to read a text file without problems. Can anyone please point out what I'm doing wrong? The file is processed as it is found - without a file name extension.my $a = 0; while (@fNameArray) { if(-d substr($fNameArray[$a], 1, -2)) { $dirName = substr($fNameArray[$a], 1, -2); #directory name is allocated to a scalar for reuse. }#end if elsif(! -d substr($fNameArray[$a], 1, -2)) { $data = read_file($dirName.'/'.substr($fNameArray[$a], 1, -1)); }#end elsif $a++; }#end while
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Slurp read_file error
by moritz (Cardinal) on Aug 12, 2010 at 09:55 UTC | |
|
Re: File::Slurp read_file error
by fod (Friar) on Aug 12, 2010 at 11:49 UTC | |
by patt (Scribe) on Aug 12, 2010 at 16:01 UTC | |
|
Re: File::Slurp read_file error
by patt (Scribe) on Aug 12, 2010 at 11:38 UTC | |
by roboticus (Chancellor) on Aug 12, 2010 at 13:01 UTC | |
by patt (Scribe) on Aug 12, 2010 at 14:33 UTC |