Loading ...
Sorry, an error occurred while loading the content.

Loop problem - Newbie problem

Expand Messages
  • pmccreath
    Hello All, I would appreciate any advice, I m trying to split an email body file into seperate header files, using the code below. #!/usr/bin/perl -w use
    Message 1 of 2 , May 3, 2002
    View Source
    • 0 Attachment
      Hello All,
      I would appreciate any advice,
      I'm trying to split an email body file into seperate header files,
      using the code below.

      #!/usr/bin/perl -w
      use File::Copy; # für copy()
      use Env; # für umgebungvariablen
      $dfile="dfg42ElsX07051";
      $numpos=0;

      open (DFILE, "< $dfile");
      open (OUT, "> output");

      foreach $line (<DFILE>)
      {
      if ( $line =~ /--Message/)
      {
      $x = $. ;
      print OUT "$x :within \n";
      $numpos=$numpos+1;
      $new="header_";
      open (NEW, "> $new$numpos") or die "can't open $new_$numpos";
      print OUT "$new$numpos\n" ;
      }
      print OUT "$x \n";
      print NEW $line if $x .. /--M/i ;
      print OUT "$new$numpos: after if \n" ;
      } # End of numb pos loop

      close (DFILE) ;
      print OUT "$numpos:\n" ;
      copy ("header_$numpos", "header_final_1");
      copy ("header_1", "header_1a");
      copy ("header_2", "header_2a");
      copy ("header_3", "header_3a");
      copy ("header_4","header_4a");

      Everything *seems* to work fine and i get the correct number of files
      produced. However i cannot then reference any data in the last file,
      in the above example , header_4a is always blank,although the output
      in header_4 is correct. If i have a file with 10 headers, again the
      same problem. i cannot access the data in the last file.

      If i've missed an FAQ, please accept my apologies and point me in the
      right direction,

      Thanks in advance,

      Peter McCreath
    Your message has been successfully submitted and would be delivered to recipients shortly.