develooper Front page | perl.beginners | Postings from October 2009

Larry's filename fixer

Thread Next
Felix Dorner
October 14, 2009 15:45
Larry's filename fixer
Message ID:

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 $_;
} s/\.orig// httpd.conf.orig

will rename httpd.conf.orig to httpd.conf. But it also works with wildcards: 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.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About