On 2006-11-23, IJALAB <> wrote:
>
>
> I am trying to take the files as command line arguments and do some
> formatting to the files based on their extensions. I am getting error
> in the file open when i use $ARGV[$i]
See below.
> Also, I am assigning a fixed name to my files. can i dynamically do
> them based on my input file names?
Of course. Parse the input file name for what you want, then
use that parsed name as the name of the output file. Read perlreref
and/or perlretut for help in this area.
> print $#ARGV;
use strict;
use warnings;
> $copypath = "<path>";
> for ($i=0;$i<=$#ARGV;$i= $i + 1)
This is a yucky-looking idiom. Better to use
for my $filename (@ARGV)
Then you can address each file as $filename in your for loop
instead of as $ARGV[$i].
> $b0 = system("copy $ARGV[$i] $copypath\\scripts");
File::Copy is preferable to spawning a subshell.
> $extn = substr($ARGV[$i],-4,4);
Are all your extensions four characters? Mine aren't.
> #Error here!!!
> open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";
If you read perldoc -f open, you'll notice a lot of references to
the special variable $!, which is the error message that a system
call returns. If you include it, then you will see exactly why
your open is failing.
--keith
--
kkeller-
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information