Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thank you very much for your help. This is my last coding after some modification based on your advise. Please guide me if I am wrong.
#!/usr/bin/perl -w use Cwd; use warnings; use strict; use Getopt::Long; use constant FILEHDR => 4; use constant CDRLEN => 286; my ($trace, $help, $infile); my $swap = ''; my $indir = getcwd; my $outdir = getcwd; GetOptions ( "h|help" => \$help, "filename|f=s" => \$infile, "swap|s" => \$swap, "input|i=s" => \$indir, "output|o=s" => \$outdir, "trace|t" => \$trace ) or usage(); sub usage { exit; } my $outfile = $infile; my $data; if ($infile) { #open (OUTPUT, ">$outdir/$outfile"); open (DATA, "$indir/$infile"); binmode DATA; until (eof DATA) { read (DATA, $data, 2); my $tag = unpack "H2", substr $data,0,1,''; my $length = unpack "C", substr $data,0,1,''; $length -= 2; if ($length == "81") { $length = unpack "C", substr $data,0,1,''; $length -= 1; } if ($length > 0) { read (DATA, $data, $length); my $rec = unpack "H*", substr $data,0,$length,''; printf ("RECORD TAG : %s\n", $tag); printf ("RECORD LENGTH : %s\n", $length); printf ("RECORD : %s\n", $rec); } } close(DATA); #close(OUTPUT); }

In reply to Re^4: Problem on substr record on binary file by bh_perl
in thread Problem on substr record on binary file by bh_perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found