It's not at all clear to me how B::Deparse makes it obvious for people not familiar with seek... OTOH, Devel::Peek does. This is on Linux:
open my $fh, '>', 'junk.dat' or die $!; for ( 1 .. 4 ) { seek $fh, $_ * 80, 0; print $fh $_ x 78, "\r\n"; } open $fh, '<', 'junk.dat' or die $!; while ( <$fh> ) { use Devel::Peek; Dump $_; }
output:
SV = PV(0x189fd70) at 0x18c0a38 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x18a4610 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 +\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ +0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0001111111111111111111111111111 +11111111111111111111111111111111111111111111111111\r\n"\0 CUR = 160 LEN = 200 SV = PV(0x189fd70) at 0x18c0a38 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x18a4610 "2222222222222222222222222222222222222222222222222222 +22222222222222222222222222\r\n"\0 CUR = 80 LEN = 200 SV = PV(0x189fd70) at 0x18c0a38 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x18a4610 "3333333333333333333333333333333333333333333333333333 +33333333333333333333333333\r\n"\0 CUR = 80 LEN = 200 SV = PV(0x189fd70) at 0x18c0a38 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x18a4610 "4444444444444444444444444444444444444444444444444444 +44444444444444444444444444\r\n"\0 CUR = 80 LEN = 200
So, when you seek past the end of file, it's as if the filesystem fills that part of file (0 .. 79 bytes in our case) with zero bytes (actually it creates a 'hole' in the file, which, when read, returns zeros - apparently NTFS also does that?). These zero bytes are then actually printed, just not displayed on the terminal:
$ perl -E 'say "\0\0\0ABC" ABC $ perl -E 'say "\0\0\0ABC"' | perl -nE 'printf "%vx\n", $_' 0.0.0.41.42.43.a

In reply to Re: Position in seek() confusion by Anonymous Monk
in thread Position in seek() confusion by stevieb

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.