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

Re: [PBML] merging multiple files

Expand Messages
  • RSS
    The problem seems to be in file read read(INPUTFILE, $data, $size, $offset); The offset here i guess is the offset to place the read data at some other
    Message 1 of 2 , Aug 1, 2002
    • 0 Attachment
      The problem seems to be in file read "read(INPUTFILE, $data, $size,

      The offset here i guess is the offset to place the read data at some other
      place other than the beginning of the $data and not the file offset.

      You can use "seek" to move to that file position where offset can be

      - RSS

      <mustang97_gt@ To: perl-beginner@yahoogroups.com
      yahoo.com> cc:
      Subject: [PBML] merging multiple files
      Please respond

      Hi all,

      I'm having trouble with merging multiple files together.
      Here is a small example of what I'm trying to do:

      file1.dat file2.dat file3.dat
      12345 abcde ABCDE
      67890 fghij FGHIJ
      12345 klmno KLMNO
      67890 pqrst PQRST
      12345 uvwxy UVWXY

      Given an order list (2, 3, 1) and a size number like 1,
      I'd like to get an output file that looks like


      The code I have now is as follows:

      @order = (2,3,1);
      $size = 1;

      #place the file in the proper order
      for($i=0; $i<@order ;$i++) {
      $number = $order[$i];
      $filename[$i] = "file".$number.".dat";
      # printf("file $i = $filename[$i]\n");

      open(OUTPUTFILE, ">dataout.dat");
      #I'd like to loop until EOF but don't know how
      for ($j=0;$j<10; $j++) {
      for($i=0; $i<@order ;$i++) {
      $data = "";
      open(INPUTFILE, $filename[$i]);
      $offset = $size*$j;
      read(INPUTFILE, $data, $size, $offset);
      $data =~ s/\n//g;
      print(STDOUT "data = $data \n");
      print(OUTPUTFILE "$data");

      The output that I get for this case though is

      Can anyone tell me what errors I've made in the code?
      Am I not reading the file properly? It looks like
      the offset is not working to me. If anyone has any suggestions
      on how to accomplish this task, perhaps in an easier way,
      I'd greatly appreciate it.

      Thanks in advance,
      another perl newbie

      Unsubscribing info is here:

      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    Your message has been successfully submitted and would be delivered to recipients shortly.