Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uwm.edu!linac!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: pack and unpack Message-ID: <1991May18.130334.10085@convex.com> Date: 18 May 91 13:03:34 GMT References: <1991May15.205819.890@lighthouse.com> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 45 Nntp-Posting-Host: pixel.convex.com From the keyboard of rob@lighthouse.com (Rob Kedoin): :I was trying to use pack for the first time today and I can't get the :following test program to do what I want: : :--- cut here --- :#!/usr/bin/perl :# packTest. Experiment with pack. :# :# Expected output was: :# foo :# bar :# baz :# :# Actual output is: :# f :# b :# b : :$struct = pack("aaa", "foo", "bar", "baz"); : :($foo, $bar, $baz) = unpack("aaa", $struct); : :print "$foo\n"; :print "$bar\n"; :print "$baz\n"; :--- cut here --- : :Does anyone know why I would only get the first character of the :string and how to fix this. An 'a' format is just one ascii character. Structures tend to be fixed format. You need to specify how long each string is, or at most use a* for the last one. $fmt = 'a10' x 3; $struct = pack("aaa", "foo", "bar", "baz"); ($foo, $bar, $baz) = unpack("aaa", $struct); This doesn't really buy you very much unless you're reading fixed-format (and often binary) records. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."