Re: how to write a "od -bc" like function?



"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>

.



Relevant Pages

  • Re: Excel slow on saving
    ... she makes a trifle to die for. ... The Chicken Soup recipe failed. ... After opening a file 1.539Kb, I resorted and closed the file ... I have an ME defrag engine on my Win98 machine. ...
    (microsoft.public.excel.newusers)
  • Re: Amusing problem about DC polarity
    ... The problem is to experimentally determine the correct DC polarity ... without opening the box and without letting the box die. ...
    (sci.electronics.design)
  • Re: Amusing problem about DC polarity
    ... The problem is to experimentally determine the correct DC polarity ... without opening the box and without letting the box die. ...
    (sci.electronics.design)
  • Re: Amusing problem about DC polarity
    ... The problem is to experimentally determine the correct DC polarity ... without opening the box and without letting the box die. ...
    (sci.electronics.design)
  • Re: RAM Upgrade Question
    ... Without opening the box, ... > determine what type of RAM I need to buy for upgrading? ... If the thing has been threatening to die for a while, ...
    (sci.med.transcription)