Click here to get back home

perl pack string

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
perl pack string unxl3arn3r 03-24-2008
Posted by John W. Krahn on March 24, 2008, 6:29 pm
Please log in for more thread options
unxl3arn3r wrote:
> Gurus
> I seem to be unable to pack a string padded with nulls and containing
> the length of the string prepended to it. This is my code snippet,
> where am i going wrong ?
>
> $message1 = pack("l! a*",1, "This is a test,This program is free
> software,you can redistribute it terms as Perl network, This is why I
> said to talk");
> msgsnd($queue,$message1,0);
>
> In my msgrcv i only want to recieve upto 100 characters. If i send a
> string greater than 100 my script receiving the message fails.

$ perl -le'
use Data::Dumper;
$Data::Dumper::Useqq = 1;

my $x = pack q[l!/Z*], "This is a test,This program is free software,you
can redistribute it terms as Perl network, This is why I said to talk";

print Dumper $x;
'
$VAR1 = "wThis is a test,This program is free software,you can
redistribute it terms as Perl network, This is why I said to talk";


And then to unpack:

$ perl -le'
use Data::Dumper;
$Data::Dumper::Useqq = 1;

my $x = unpack q[l!/Z*], "wThis is a test,This program is free
software,you can redistribute it terms as Perl network, This is why I
said to talk";

print Dumper $x;
'
$VAR1 = "This is a test,This program is free software,you can
redistribute it terms as Perl network, This is why I said to talk";


If you want to limit the size of the string to 100 characters:

perldoc -f substr



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Similar ThreadsPosted
strange output of pack in perl 5.8.0 September 9, 2004, 7:36 pm
"RFC": re [un]pack() September 10, 2004, 12:15 am
pack 'C3U*' not same as pack 'C3(xC)*' June 23, 2005, 7:48 am
Need help with pack October 1, 2005, 11:00 pm
Trying to force 32-bit in pack() October 12, 2004, 5:19 pm
pack and unpack ? January 9, 2005, 11:37 am
pack problem? August 27, 2006, 11:17 pm
sprintf or pack January 30, 2007, 7:33 am
pack /unpack issue November 10, 2005, 7:48 pm
pack, unpack and 64-bit values February 9, 2006, 12:55 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap