I've never had a need to use seek() in my Perl years, so after I got looking at a piece of code BrowserUK posted earlier today, I thought I'd ask about it.
In the below code in the seek $fh, $_ *80, 0; line, I would believe that it would set the cursor to column 80 (times the multiple in the while(...)), but it then proceeds to print 78 chars to the file. When I look at the file, all lines start at column 0.
#! perl -slw use strict; use threads; open my $fh, '>', 'junk.dat' or die $!; $_->join for map { async { seek $fh, $_ *80, 0; print $fh $_ x 78; }; } 1 .. 4; close $fh; open $fh, '<', 'junk.dat' or die $!; print while <$fh>; close $fh;
perldoc -f seek doesn't help it click for me. Can someone advise what I'm missing in the above code? I did modify the code to try to understand, but the reason why things start at col 0 elude me.
-stevieb
In reply to Position in seek() confusion by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |