in reply to Re^4: Offset Reading - two files
in thread Offset Reading - two files

seek does not take a length ($2 as its third parameter. If you changed that to:

perl -sple"BEGIN{open BIG};($1,$2)=split;seek(BIG,$1,$2);read(BIG,$_,0 +)" -- -BIG=bigfile.dat index.dat >outfile.dat

It might work.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.

Replies are listed 'Best First'.
Re^6: Offset Reading - two files
by gio001 (Acolyte) on Dec 14, 2012 at 15:46 UTC
    I have tried:

    perl -sple 'BEGIN{open BIG};($1,$2)=split;seek(BIG,$1,0);read(BIG,$_,$2)' -- -BIG=bigfile.dat index.dat >outfile.dat

    and I received the following:

    Modification of a read-only value attempted at -e line 1, <> line 1

    Thanks,

      This seems to work:

      C:\test>type junk.dat a_12_3_5- k_3_4_6-a_12_3_5- q_1_5_7_9- q_1_5_7_9- a_9_4_5-c_3_4_6- c_3_4_6-r_4_5_7- b_1_1_3- v_1_5_7- d_12_4_5-e_4_5_6- g_5_6_7-d_6_8_6- b_1_1_7-f_3_8_7_8-d_4_1_4- d_4_1_5-b_1_1_7-f_3_8_3 b_1_1_7-f_3_8_7_8-d_4_1_4- e_3_3_1-f_3_8_7-f_21_3_1-b_1_1_7-a_1_1_1- C:\test>perl -swple"BEGIN{open BIG};($o,$s)=split;seek(BIG,$o,0);read( +BIG,$_,$s)" -- -BIG=junk.dat con >junk2.dat 1 10 20 10 5 10 30 20 ^Z C:\test>type junk2.dat _12_3_5- k 12_3_5- q_ 3_5- k_3_4 _1_5_7_9- q_1_5_7_9-

      I leave it to you to work out why yours doesn't.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        I will try to work this out, the difference I see is that my input BIG file is a 'single' record, there are no record separator in it, each 'record' is identified by offset and length from the index file, somewhat different from what you illustrated. Is the seek command behaving differently in my case? I even tried:

        perl -sple 'BEGIN{open BIG};($1,$2)=split;read(BIG,$_,$2,$1)' -- -BIG=$2 index.dat > output.dat

        with the same error . Thanks

        Thanks so much. I got this to work. <p>perl -sple 'BEGIN{open BIG};($offse,$recl)=split;seek(BIG,$offse,0);read(BIG,$_,$recl)' -- -BIG=datain index.dat >out </p> Thanks for the support. I promise I will put more time in learning the basics before bothering you again. Bye

      You are trying to assign to $1 and $2 but these are special variables that are only set by successful regular expression match captures and are read-only otherwise (see Extracting matches). Use normal scalar variables with names that are something meaningful, like $offset and $reclen perhaps.

      I hope this is helpful.

      Cheers,

      JohnGG

      use splain or diagnostics to get more verbose error message

      Read about the variable you're using with perldoc -v '$1' and stop that :)