Help!

Fair warning: Though I've found Perl to be extremely useful and not an inconsiderable amount of fun, I am still somewhat new to the language.

I'm trying to use unpack() to convert packed binary data into ASCII. I'm using the program below, but the output is identical to the input! I seem to be missing some basic theory about what packed data is..

Is the Perl unpack() function not based on the same concepts that packed data fields employ? I wish I could be more lucid, but I'm pretty much at a loss for what to do..

Here's the code: (the field I'm trying to unpack is supposed to be a sequence number on a fixed-length record.)

$description = "Unpacks packed data."; ($ARGV[1]eq"")?&usage:nop; #ensure the proper number of parameters $ifn=$ARGV[0];$ofn=$ARGV[1]; open IFN, "$ifn" or die "Can't open $ifn:$!\n"; open OFN, ">$ofn" or die "Can't open $ofn:$!\n"; print "$0:$ifn->$ofn..\n"; binmode(IFN); while(<IFN>){ ($.%1000)?nop:print "\rRecords processed:$."; $seq = substr($_,1,7); ###################################################### $seqout = unpack("A14", $seq); #<--Here's the problem ###################################################### print OFN "Input[$.]: >>$seq<<\n"; print OFN "Output[$.]: >>$seqout<<\n\n"; }; print "\rRecords processed:$.\n"; print "Done.\n"; exit; ##############NORMAL TERMINATION HERE############## sub usage{ print "$0\n\n"; print "$description\n\n"; ($fn) = ($0 =~/(.*)\.(.*)/); print "USAGE: perl $fn <inputfile> <outputfile>\n\n"; exit; };

Some sample output:

Input[1]: >>  << Output[1]: >> << Input[2]: >> i? << Output[2]: >> i?<< Input[3]: >>   << Output[3]: >>  <<

My final question: How do I take this input and extract the information from it?

-- "The snark was a boojum, you see.."


In reply to Unpacking binary data with unpack()? by PiEquals3

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.