I was intrigued by the question and had a go at trying to do it. I often find myself using a hex dump utility to 'see what's actually there'. Looking in Perl would be useful. I've not had experience with binary mode before so it was about time I did.
(dummy.txt has 99 'a's and a 'b')
use strict;
use warnings;
use Fcntl;
my $stream;
# 'or die ...' removed for clarity
sysopen(DUMMY, "dummy.txt", O_RDWR | O_BINARY);
my $bytes_read = read DUMMY, $stream, 128;
for ( my $i=0; $i<= $bytes_read; $i++ ){
my $char = substr( $stream, $i, 1 );
print $i, ": ", ord( $char ), " => *", $char, "*\n";
}
produces...
0: 97 => *a*
1: 97 => *a*
2: 97 => *a*
3: 97 => *a*
... etc
98: 97 => *a*
99: 98 => *b*
100: 0 => **
Nowhere near it (not even new lines). I found the docs quite intimidating, clearly the cross platform issues are tricky. (I was reading one article that mentioned CP/M!)
Any pointers?
activestate 5.8 on winXP
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.