Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

perl script .. Help needed

Status
Not open for further replies.

smileysam

Member level 4
Joined
Feb 19, 2006
Messages
76
Helped
12
Reputation
24
Reaction score
3
Trophy points
1,288
Activity points
1,830
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);
 

This code works ok.

Code:
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]: $! ";
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top