SPUG: pack and unpack

Richard Wood wildwood_players at yahoo.com
Wed Aug 27 17:04:31 CDT 2003


Ben, Dan, Andy, 

Thanks for your responses.  

Ben, your code is certainly cleaner and seems to be
heading me in the right direction.  I don't seem to be
getting good values out but that just requires more
thought and experimentation. (by the way did you mean
to use an "A" instead of a "Z" for ASCII?  Z is not a
meta character in pack. 

> } elsif ($type == 2) {
>   $decoded_value = unpack "Z$count", $value;

Dan, I appreciate your pointing toward Image::Info.  I
am interested in the meta data but that is just the
ground work.  The real problem lies in interpreting
the scan lines and making decision based on bit
patterns.  I will consider incorporating the
Image::Info methods into the program.  

Andy, I like your style!

I guess I am on the right foot, sounds like trial and
error will be the order of the day until I get it
totally correct.  

Thanks for your ideas.

Rich Wood


--- Ben Reser <ben at reser.org> wrote:
> On Wed, Aug 27, 2003 at 11:47:39AM -0700, Richard
> Wood wrote:
> > ($tagB, $typeB, $countB, $val1B, $val2B, $val3B,
> > $val4B) = unpack "B16B16B32B8B8B8B8", $buffer;
> > $tagC = bin2dec($tagB);
> > $typeC = bin2dec($typeB);
> > $countC = bin2dec($countB);
> > 
> > sub bin2dec {
> >     return unpack("N", pack("B32", substr("0" x 32
> .
> > shift, -32)));
> > }
> 
> Why not do this:
> 
> 
> seek(TIF, $offset, 0) or die "Seek $i: $!\n";
> read(TIF, $buffer, 12);
> ($tag, $type, $count, $value) = unpack "nnNB32",
> $buffer;
> if ($type == 1) {
>   $decoded_value = unpack "C", $value;
> } elsif ($type == 2) {
>   $decoded_value = unpack "Z$count", $value;
> } elsif ($type == 3) {
>   $decoded_value =unpack "n", $value;
> } elsif ($type == 4) {
>   $decoded_value = unpack "N", $value;
> ...
> 
> -- 
> Ben Reser <ben at reser.org>
> http://ben.reser.org
> 
> "What upsets me is not that you lied to me, but that
> from now on I can
> no longer believe you." -- Nietzsche
>
_____________________________________________________________
> Seattle Perl Users Group Mailing List  
> POST TO: spug-list at mail.pm.org 
> http://spugwiki.perlocity.org
> ACCOUNT CONFIG:
> http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, U-District, Seattle WA
> WEB PAGE: http://www.seattleperl.org
> 


=====
Richard O. Wood
Wildwood IT Consultants, Inc.
wildwood_players at yahoo.com
425.281.1914 mobile
206.544.9885 desk

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



More information about the spug-list mailing list