I
IJALAB
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]
Also, I am assigning a fixed name to my files. can i dynamically do
them based on my input file names?
print $#ARGV;
$copypath = "<path>";
for ($i=0;$i<=$#ARGV;$i= $i + 1)
{
$b0 = system("copy $ARGV[$i] $copypath\\scripts");
$b1 = chdir ("$copypath\\scripts");
$extn = substr($ARGV[$i],-4,4);
print $extn, "\n";
print $ARGV[$i];
$file = $ARGV[$i];
if ($extn == ".txt")
{
#Error here!!!
open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";
open ($ofh, '>OutFile.txt') or die "Cannot open Output File:";
while (my $line = <$fh>) {
<Formatting here>
}
close $fh;
close $ofh;
$b3 = chdir ("$copypath");
}
elsif ($extn == ".csv")
{
#Error here!!!
open my $f2h, '<', '$ARGV[$i]' or die "Cannot open InputFile.txt: ";
open my $of2h, '>', 'OutFile.csv' or die "Cannot open Output File:";
while (my $line = <$f2h>) {
<Formatting exp here>
}
close $f2h;
close $of2h;
$b3 = chdir ("$copypath");
}
}
thanks
bala
formatting to the files based on their extensions. I am getting error
in the file open when i use $ARGV[$i]
Also, I am assigning a fixed name to my files. can i dynamically do
them based on my input file names?
print $#ARGV;
$copypath = "<path>";
for ($i=0;$i<=$#ARGV;$i= $i + 1)
{
$b0 = system("copy $ARGV[$i] $copypath\\scripts");
$b1 = chdir ("$copypath\\scripts");
$extn = substr($ARGV[$i],-4,4);
print $extn, "\n";
print $ARGV[$i];
$file = $ARGV[$i];
if ($extn == ".txt")
{
#Error here!!!
open ($fh, '<$ARGV[$i]') or die "Cannot open Inputfile: ";
open ($ofh, '>OutFile.txt') or die "Cannot open Output File:";
while (my $line = <$fh>) {
<Formatting here>
}
close $fh;
close $ofh;
$b3 = chdir ("$copypath");
}
elsif ($extn == ".csv")
{
#Error here!!!
open my $f2h, '<', '$ARGV[$i]' or die "Cannot open InputFile.txt: ";
open my $of2h, '>', 'OutFile.csv' or die "Cannot open Output File:";
while (my $line = <$f2h>) {
<Formatting exp here>
}
close $f2h;
close $of2h;
$b3 = chdir ("$copypath");
}
}
thanks
bala