how to controll end of file..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fetaelin
    New Member
    • May 2007
    • 16

    how to controll end of file..

    Hi..
    I need to read from File1 and File2, and write the first row in file1 + first row in file2 in file3.
    if file1 ends before file2, then the program is finnished,
    if file2 ends before file1 then it should begin from the beginning untill file 1 ends,
    the code I have now is not complete. can you please help me to finnish it ?
    thanx.
    Code:
    #!/usr/bin/perl
    open(file1, "SA2007");
    open(file2, "INTJ2005");
    open(file3, ">INTJ2006.del");
    while (!(eof(file1)) {
    	if((eof(file2)){
    		#go to begining of file (how to do that ? 
    	}
    	else{
    		# copy first row of file1 > $fr1
    		# copy first row of file2 > $fr2
    		# print "$fr1:$fr2" > file3
    	}
    }
    
    close file1;
    close file2;
    close file3;
  • mehj123
    New Member
    • Aug 2007
    • 55

    #2
    I guess you can use seek FILEHANDLE,POSI TION,WHENCE , where you can give WHENCE as SEEK_SET and POSITION as 0. I hope it works..

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Originally posted by fetaelin
      Hi..
      I need to read from File1 and File2, and write the first row in file1 + first row in file2 in file3.
      if file1 ends before file2, then the program is finnished,
      if file2 ends before file1 then it should begin from the beginning untill file 1 ends,
      the code I have now is not complete. can you please help me to finnish it ?
      thanx.
      [code=perl]
      #!/usr/bin/perl
      open(file1, "SA2007");
      open(file2, "INTJ2005") ;
      open(file3, ">INTJ2006.del" );
      while (!(eof(file1)) {
      if((eof(file2)) {
      #go to begining of file (how to do that ?
      }
      else{
      # copy first row of file1 > $fr1
      # copy first row of file2 > $fr2
      # print "$fr1:$fr2" > file3
      }
      }

      close file1;
      close file2;
      close file3;

      [/code]
      I have a question. Is this school work? It sounds like it the way it is worded. I ask because it is the policy here on TSDN that we cannot do you homework for you, but can point you in the right direction if you get stuck.

      I just needed to let you know that.

      Regards,

      Jeff

      Comment

      Working...