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



jck11 wrote:
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;
my $str=<IN>;
.............
close(IN);

By the way, if the file is a exe or image type, the $str seems don't work
correctly.

Apart from the usual: three-argument "open", lexical filehandles, and explicit '<':
1. if you're dealing with binary files, you must tell perl this: "binmode IN;" after open(...), and
2. you're not reading "strings" of *characters* but "blocks" of *binary* data, so better use "read(...)".

so
perldoc -f binmode
perldoc -f read

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html

.



Relevant Pages

  • Re: how do I convert a file into its 8 bit 0/1 pattern ?
    ... I suspect that what you think you are saying here is something more ... Examples like this should be easily found in any Perl tutorial or reference. ... Actually in recent Perl openand binmode() can be combined. ... perldoc -f binmode ...
    (comp.lang.perl.misc)
  • Re: binmode() setting FH to ascii
    ... >> binmode FILEHANDLE, LAYER ... >> perldoc PerlIO ... especially if your sure your text is all 7-bit ascii, ...
    (perl.beginners)
  • Re: MIME::Entity , decoding Base64 image/jpg
    ... > i am not sure what u mean by binmode? ... I see that you are not familiar with the perl documentation. ... there should be an utility called 'perldoc' installed on your system. ... or html files. ...
    (comp.lang.perl.modules)
  • Re: start of central directory not found, Corrupt zip file
    ... Im kinda new to all of this, but im almost 100% sure that will slove ... following at your command prompt: ... perldoc -f ... binmode() should be called after openbut before ...
    (perl.beginners)