|
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
|