Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^6: Offset Reading - two files

by gio001 (Acolyte)
on Dec 14, 2012 at 15:46 UTC ( #1008861=note: print w/ replies, xml ) Need Help??


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

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,


Comment on Re^6: Offset Reading - two files
Select or Download Code
Re^7: Offset Reading - two files
by BrowserUk (Pope) on Dec 14, 2012 at 16:04 UTC

    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

        You are still trying to use the readonly variables $1 & $2, hence the error message.

        I suggest that you learn simple Perl, before you try to do complicated things with it. If you do not have enough time to learn, employ someone to do it for you.


        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

      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
Re^7: Offset Reading - two files
by Anonymous Monk on Dec 14, 2012 at 16:04 UTC

    use splain or diagnostics to get more verbose error message

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

Re^7: Offset Reading - two files
by johngg (Abbot) on Dec 14, 2012 at 16:11 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008861]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-22 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls