Okay, I've changed the code to
my $dir=shift;
s/^'//, s/'$// for $dir;
print '$dir =',"$dir\n";
print '@ARGV=(',join(',',@ARGV),")\n";
Not that I despise join(), but IMHO it would be more terse having it
take place under the curtain, a la (e.g.)
{
local $,=',';
print "@ARGV\n";
}
my @files=@ARGV;
my @dirs=grep -d, glob abs_path($dir);
if $dirs==0 {
die "$dir dosn't match any directory names:\n";
}
Huh?!? Are you running Perl6? If not then this has to be:
if ($dirs==0) {
# ^ ^
die "$dir dosn't match any directory names:\n";
}
But then it's also @dirs, not $dirs.
Still running Perl6, I see... ;-)
Also... well, here $dir at least does exist. But @dirs is again what
you really want, isnt'it?
print "$dir matches multiple directory names:\n";
die join " \n" @dirs, "\n";
Is there any good reason you are mixing print() and die() statements?
Are you aware you will be printing to two different fd's?
Also, the last line has an error: join() wants comma separated args,
but in that case you must also add parenthesis to avoid the last "\n"
being considered as another argument to join().
Moreover, out of curiosity: why " \n" instead of "\n"?
All in all I'd rewrite the whole fragment as:
@dirs or die "`$dir' doesn't match any directory name\n";
die "`$dir' matches multiple directory names:\n",
map "$_\n", @dirs if @dirs>1;
Are you referring to the issue of $1 versus \1?
No, I suggested you to search 'WARNING' in perldoc perlre. This turns
out to be:
| WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in
| the program, it has to provide them for every pattern match. This may
| substantially slow your program. Perl uses the same mechanism to produce
| $1, $2, etc, so you also pay a price for each pattern that contains
| capturing parentheses. (To avoid this cost while retaining the grouping
| behaviour, use the extended regular expression "(?: ... )" instead.) But
| if you never use $&, $` or $', then patterns *without* capturing
| parentheses will not be penalized. So avoid $&, $', and $` if you can,
| but if you can't (and some algorithms really appreciate them), once
| you've used them once, use them at will, because you've already paid the
| price. As of 5.005, $& is not so costly as the other two.
them into production code. Is it considered good style to use a
here-doc when the output is only a line or two?
One or two lines... hmmm, I would say: no. Just a few more and then:
yes. In both cases this is largely a matter of personal tastes.
Michele