in reply to hash assignment using map with multiple statements

For robustness and clarity, you ought to use well-defined modules instead of split and s///
use Text::ParseWords; use File::Basename; my %testhash = map { my ($file, $dir, $suffix) = fileparse((shellwords $ +_)[-1], '\.txt'); $file => $file . $suffix } @teststr;

Replies are listed 'Best First'.
Re^2: hash assignment using map with multiple statements
by diomedea (Sexton) on Sep 22, 2008 at 09:48 UTC
    thanks plenty to think about here, some background info, i am loading c5k filenames as an initialisation process of a larger app, so perhaps File::Basename is a better way to go currently I do this ( i cant  `ls -1` as ls borks with too many arguments error)
    my @teststr = `find $filearea -name "*.txt" -ls`;
    the current design probably isnt great, but Id be interested in hearing opinions on the relative speed of the different solutions: e.g. is a system call likely to be more expensive than the module? ill try and do some benchmarking myself thanks