If one has to spend significant time trying to undertstand the test snippet, how can one really know what is really being tested. What follows are tests which are much more straightforward:
{ open(local *FILE, '>', 'delete_me.txt') or die; print FILE "Test file line $_\n" for 1..4; } { print("Two Handles\n\n"); open(local *FILE1, '<', 'delete_me.txt') or die; open(local *FILE2, '<', 'delete_me.txt') or die; print scalar <FILE1>; print scalar <FILE1>; print scalar <FILE1>; print("$.\n"); # 3 (Line num for FILE1) print scalar <FILE2>; print("$.\n"); # 1 (Line num for FILE2) print scalar <FILE2>; print("$.\n"); # 2 (Line num for FILE2) print scalar <FILE1>; print("$.\n"); # 4 (Line num for FILE1) } print("--\n"); { print("Does 'seek' Count As an Access?\n\n"); open(local *FILE1, '<', 'delete_me.txt') or die; open(local *FILE2, '<', 'delete_me.txt') or die; print scalar <FILE1>; print scalar <FILE1>; print scalar <FILE1>; print("$.\n"); # 3 (Line num for FILE1) seek(FILE2, 0, 0) or die; # seek counts as an access. print("$.\n"); # 0 (Line num for FILE2) print scalar <FILE1>; print("$.\n"); # 4 (Line num for FILE1) } print("--\n"); { print("Does 'eof' Count As an Access?\n\n"); open(local *FILE1, '<', 'delete_me.txt') or die; open(local *FILE2, '<', 'delete_me.txt') or die; print scalar <FILE1>; print scalar <FILE1>; print scalar <FILE1>; print("$.\n"); # 3 (Line num for FILE1) eof(FILE2); # eof counts as an access. print("$.\n"); # 0 (Line num for FILE1) print scalar <FILE1>; print("$.\n"); # 4 (Line num for FILE1) } print("--\n"); { print("Does 'read' Count As an Access?\n\n"); open(local *FILE1, '<', 'delete_me.txt') or die; open(local *FILE2, '<', 'delete_me.txt') or die; print scalar <FILE1>; print scalar <FILE1>; print scalar <FILE1>; print("$.\n"); # 3 (Line num for FILE1) read(FILE2, my $buf='', 1) or die; # read doesn't count print("$.\n"); # 3 (Line num for FILE1) print scalar <FILE1>; print("$.\n"); # 4 (Line num for FILE1) } print("--\n"); { print("Assigning to \$.\n\n"); open(local *FILE, '<', 'delete_me.txt') or die; print scalar <FILE>; print scalar <FILE>; print scalar <FILE>; print("$.\n"); # 3 $. = 7; # Works like "#line" print("$.\n"); # 7 print scalar <FILE>; # Prints the 4th line. print("$.\n"); # 8 } unlink 'delete_me.txt';

In reply to Re: $. - smarter than you might think by ikegami
in thread $. - smarter than you might think by GrandFather

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.