Iam trying to copy content of one file into another .
The code is not working and hangs and the content is not copied into file 2
I have pasted the code. Any comment will be useful . thanks.
# copy one file into another.
$len = $#ARGV + 1;
print($len);
print("$ARGV[0]\n");
print("$ARGV[1]\n");
if( (open(fileptr1,$ARGV[0])) == 0)
{
die("Error in opening the file");
}
else
{
print("File 1 opened\n");
}
print("Iam here");
if( (open(fileptr2,">>".$ARGV[1])) == 0)
{
die("Error in opening the file");
}
else
{
print("File 2 opened\n");
}
while(fileptr1 ne "")
{
$input = <fileptr1>;
print ($input);
print fileptr2 ($input);
}
close(fileptr1);
close(fileptr2);
open(IN,$ARGV[0]) || die "Cannot open $ARGV[0] for reading: $! ";
open(OUT, ">$ARGV[1]") || die "Cannot create $ARGV[1]: $! ";
while(<IN>){
print OUT $_;
}
close(IN) || die "Cant close $ARGV[0]: $! ";
close(OUT) || die "Cant close $ARGV[1]: $! ";