Re: how to write a "od -bc" like function?
- From: "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 04:21:05 GMT
"jck11" <jck11@xxxxxxxxxxxxxxxxx> wrote in
news:fb7vth$fq5$1@xxxxxxxxxxxxxxxxx:
hi all
Could any one give me a direction to write a function to match the
unix-like function "od -bc" do.
Now I only get the idea of opening the file.
open(IN, "filename")or die;
Prefer the three-argument form of open.
At least give an indication why the call failed.
open my $in, '<', 'filename'
or die $!;
my $str=<IN>;
Here, you read only one line from the file.
.............
close(IN);
By the way, if the file is a exe or image type, the $str seems don't
work correctly.
Study my hexdump example at:
http://www.unur.com/comp/ppp/hexdump.html
You should be able to adapt that to produce the same output od -bc
produces by changing only the hexdump_line subroutine.
Keep in mind:
You must read the input file in binary mode.
Line-by-line processing does not mean much here as you are trying to
display fixed sized blocks of bytes.
Sinan
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
.
- References:
- how to write a "od -bc" like function?
- From: jck11
- how to write a "od -bc" like function?
- Prev by Date: Re: how to write a "od -bc" like function?
- Next by Date: Re: how to write a "od -bc" like function?
- Previous by thread: Re: how to write a "od -bc" like function?
- Next by thread: Re: how to write a "od -bc" like function?
- Index(es):
Relevant Pages
|
|