Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Position in seek() confusion

by BrowserUk (Patriarch)
on Jul 01, 2015 at 02:57 UTC ( [id://1132748]=note: print w/replies, xml ) Need Help??


in reply to Position in seek() confusion

That was a crude demonstration knocked up in haste. If you run it, you'll find that in addition what you've noticed, it also prints the lines double spaced.

This is due to the use of -l on the shebang line. Newlines are added when the lines are printed to the file and then again when they are read back and printed to STDOUT.

I took the liberty of discarding the spaces when posting. If you want a better version, try:

#! perl -sw use strict; use threads; use threads::shared; my $sem :shared; open my $fh, '>:raw', 'junk.dat' or die $!; $_->join for map { async { for my $i ( 0 .. 999 ) { lock $sem; seek $fh, $i*320 + ($_-1)*80, 0; print $fh $_ x 79, "\n"; } }; } 1 .. 4; close $fh; open $fh, '<', 'junk.dat' or die $!; print while <$fh>; close $fh; __END__ C:\test>t-write.pl 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 1111111111111111111111111111111111111111111111111111111111111111111111 +11111111 2222222222222222222222222222222222222222222222222222222222222222222222 +22222222 3333333333333333333333333333333333333333333333333333333333333333333333 +33333333 4444444444444444444444444444444444444444444444444444444444444444444444 +44444444 ...

Note: I truncated some of the output when posting.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found