BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use threads; use strict; die $! unless open my $fh, '>', 'junk.dat'; $_->join foreach (map {async sub { seek $fh, $_ * 80, 0; print $fh $_ x 78; } ;} 1..4); close $fh; die $! unless open $fh, '<', 'junk.dat'; print $_ while defined($_ = <$fh>); close $fh;
So on windows "\n" becomes the bytes "\r\n" when you print, so 78 + 2 = 80, thats the lines
so seek to 1*80 from zero print "1" 78 times followed by "\r\n"
so seek to 2*80 from zero print "2" 78 times followed by "\r\n"
so seek to 3*80 from zero print "3" 78 times followed by "\r\n"
so seek to 4*80 from zero print "4" 78 times followed by "\r\n"
Then when reading the file the first 80 chars are null ("\0") then its 1111...222...333...4444
Thats Basic debugging checklist for you
In reply to Re: Position in seek() confusion
by Anonymous Monk
in thread Position in seek() confusion
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |