output: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 $_; }
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: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
$ 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |