From: Mark Wagner

> On Wed, Oct 14, 2009 at 15:38, Felix Dorner <felix...@web.de> wrote:
>>
>> I did the best book purchase in years: The Perl Cookbook. They have an
>> example that seems to come right from Larry Wall himself. And I don't get
>> it. I can use it but I don't understand why it works with wildcards.
>>
>> $op = shift or die "Usage: rename expr [files]\n";
>> chomp (@ARGV = <STDIN>) unless @ARGV;
>> for(@ARGV) {
>>   $was = $_;
>>   eval $op;
>>   die $@ if $@;
>>   rename ($was, $_) unless $was eq $_;
>> }
>>
>>
>> #rename.pl s/\.orig// httpd.conf.orig
>>
>> will rename httpd.conf.orig to httpd.conf. But it also works with wildcards:
>>
>> #rename.pl s/\.orig// *
>>
>> will chop .orig from all files in the current directory.
>> So it assigns <STDIN> to @ARGV. But <STDIN> is just a * right? Does the
>> shell expand this, or perl? Any comments/detailed explanations welcome.
> 
> IIRC, under *nix, the shell expands it, while under Windows, Perl
> expands it.  It doesn't really matter, because by the time @ARGV is
> populated, it's been expanded and the script only ever sees the
> expansion.

This depends on which distribution of Perl you use on MS-Windows. Only a couple 
of them actually expand the wildcards.

I use this line in a batch file for testing with Camelbox on MS-Windows. Most 
mail clients will wrap it, but it should all be typed on one line. I don't know 
if the extra spaces are significant, but it works so I haven't changed it.

perl -MTest::Harness -e "@ARGV= map glob, @ARGV   if  $^O =~ /^MSWin/; runtests 
@ARGV;" t/*.t

Bob McConnell

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to