Its interesting to see myself go from reading books that teach perl that is poor form (never mentioning -w or strict) to hearing how a monk should really be putting the digital plume to scripture.
I think I am finally understanding the use of seek(); and why just copying and pasting it from another's example didnt work.

My code looked like:

open FILE, "$filename" or die $!; flock(FILE,2); seek(FILE,0,2); @entries = <FILE>; flock(FILE,8);

Yet when I went to view the contents of @entries, it was empty. I scratched my head for hours on this one since all the examples of seek I had seen seemed to call it with (FILEHANDLE,0,2). Finally, I came to some sort of enlightenment thinking that since the whence portion of the seek statement was set to 2, the @entries list is only reading from the end of the FILEHANDLE on. When I changed the entry to seek(FILEHANDLE,0,0) the outcome was more what I expected.

So, I guess I am looking for someone with more experienced robes than mine to give me the nod that this logic is correct and the moral of "never blindly copy another's code" fits the bill.

humbly -c


In reply to seek(UNDERSTANDING); by c

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.