The assignment to the array will eat up all the values so no you can't do it in just one go (if the array comes before the individual scalars; if the scalars came first it would have just worked as you have it now); you could however capture everything in @ids then use splice or pop to remove $text and $length afterwards.
Update: D'oh, yeah it'll work fine with a slice of fixed length as psini proffers below. Ned moar caffeine apparently . . .
Update 2: Well, will work with a more appropriate unpack string ("c40" returns a list of 40 characters-as-numbers, not a string of 40 characters); "a", "A", or "Z" is probably more what the OP's looking for.
use strict; use warnings; use YAML::Syck qw( Dump ); my $src = pack( "N10 a5 n", 0..9, "abcde", 99 ); my( @a, $b, $c ); (@a[0..9],$b,$c) = unpack( "N10 a5 n", $src ); print Dump( { a => \@a, b => $b, c => $c } ), "\n"; exit 0; __END__ --- a: - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 b: abcde c: 99
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: unpack() to several variables
by Fletch
in thread unpack() to several variables
by Saladino
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |