in reply to Re^4: Simple Perl file rename
in thread Simple Perl file rename

When I copy and paste your code
Since I provided 3 sets of code and output data, I am not sure which one you ran.

Let's try another approach...

> ls *.txt file1.txt file2.txt file3.txt > cat test.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; print Dumper(\@ARGV); > ./test.pl 's/foo/bar/' file*.txt $VAR1 = [ 's/foo/bar/', 'file1.txt', 'file2.txt', 'file3.txt' ]; >

My operating system in Linux. I have 3 *.txt files in my current directory. When I run my test.pl script, it simply prints out the contents of the @ARGV array, which correspond to the things which appear on the test.pl command line. The 1st thing on the command line is the string corresponding to the substitution operator. The 2nd thing on the command line is a file specifier using the standard Unix wildcard character (*), which gets expanded into 3 filenames.

Are you on a *nix OS, or are you on Windows, or a Mac?

Are you familiar with the concept of wildcard expansion?

Replies are listed 'Best First'.
Re^6: Simple Perl file rename
by clearwater (Initiate) on Jul 29, 2008 at 09:41 UTC

    Thanks a lot toolic,

    "wildcard expansion" gave me the hint I needed. To cite from another thread here Your problem is that Unix expands wildcards before passing them to the program. Windows doesn't do this, prefering to let the program carry out it's own wildcard expansion.

    Hence I just have to glob the files in my Perl script,

    @ARGV= map glob, @ARGV;

    does the trick.

    Thank you very much for your help!