Will this one liner process all the entries in the index file gathering and putting out strings from the bigfile without a need for a loop or a while?

Yes. The loop is invoked by the -p option on the command line. This tells perl to read the file given as a command line argument (index.dat above) into $_ and then print it to stdout.

The code in the -e takes the contents of $_, splits it to extract the length, reads that number of bytes from the filehandle BIG, overwriting $_. This is then (implicitly) printed with a newline due to the -l switch, and redirected to the output file by the command line processor.

The -s switch tells perl to parse the command line for options in the form -XXX=yyy. This creates a variable named XXX with the value yyy.

The BEGIN{} block uses a one-arg open to open the file for input (using the value of the BIG as the filename and storing the filehandle the glob *BIG).

The -- is required to allow Perl to differentiate between the options intended for use by perl itself, and those (-BIG=bigfile.dat) intended for use by the "script" (-e"...") in this case.

See perlrun for a better explanation of all the switched than I can give.

Also there is no use of the offset value, am I reading this right, will the read head keep moving automatically inside the bigfile, forward from the last read?

Exactly. You are essentially just reading the file sequentially. The only extra information you need, is how many bytes constitute each record.

Perl may have some weird nooks and crannies, but they're all there for very good reasons :)


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Read offset into other files by BrowserUk
in thread Read offset into other files by gio001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.