in reply to Do as I say. Not as I do
Hmm. Not sure I agree the second one is clearer than the first. A multi-line map can be hard to follow, and it's not clear to me that "Creating a new array has got to be better than mysteriously transforming one."
To a great extent, understandability is in the eye of the beholder. Nonetheless, I think a couple of very minor changes or additions to your first code would have made your intent clearer, more so than using map to cons up a new array. Here's what I'd suggest:
# Modify the input array in-place foreach my $elem (@in) { my ($count, $file) = split /\s+/, $elem; $file =~ s/^$in_prefix//; my ($campaign, $month, $fname) = split |/|, $file; $elem = { campaign => $campaign, month => $month, file => $fname, count => $count, sort => "$campaign:$month:$file" }; }
Update:
Changed split to split $elem, not $_. Thanks, runrig! (But let the goof caught by Hofmator stand. ;-)
Fixed split again. This is not my day....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Do as I say. Not as I do
by Hofmator (Curate) on Dec 17, 2001 at 22:17 UTC | |
by runrig (Abbot) on Dec 17, 2001 at 22:24 UTC |