stevieb has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Position in seek() confusion
by BrowserUk (Patriarch) on Jul 01, 2015 at 02:57 UTC | |
|
Re: Position in seek() confusion
by Anonymous Monk on Jul 01, 2015 at 02:02 UTC | |
|
Re: Position in seek() confusion
by Anonymous Monk on Jul 01, 2015 at 08:23 UTC | |
|
Re: Position in seek() confusion
by Anonymous Monk on Jul 01, 2015 at 01:34 UTC | |
|
Re: Position in seek() confusion
by locked_user sundialsvc4 (Abbot) on Jul 01, 2015 at 12:35 UTC | |
by Anonymous Monk on Jul 01, 2015 at 18:27 UTC | |
by Anonymous Monk on Jul 01, 2015 at 18:40 UTC |