SPUG: unpack

Benjamin Franks benjamin at dzhan.com
Thu Mar 14 18:45:00 CST 2002


Thanks for all the responses recommending unpack().  Here's an example
I'm trying:

	struct alpha {
	  char   *a;
	  long	 b;
	};

Now let's say the byte-string equivalent is stored in a file.  I snag it
into perl into $alpha;

	$len=length($alpha)-4;
 	($a,$b) = unpack("a$len l",$alpha);

I get the 4-byte long value correctly.  But the string for $a is
garbled or empty.

Any ideas,
--Ben


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list