[Israel.pm] pack vs. different architectures
Gaal Yahas
gaal at forum2.org
Tue Feb 22 02:01:36 PST 2005
On Tue, Feb 22, 2005 at 11:55:10AM +0200, Ephraim Dan wrote:
> > my $str =
> > pack('a8',$hdr->{id}) .
> > pack('f',$hdr->{lat}) .
> > pack('f',$hdr->{lon}) .
> > pack('f',$hdr->{t}) .
> > pack('N',$hdr->{nlev}) .
> > pack('N',$hdr->{flag});
> > syswrite(DAT,$str);
>
> A style question - why are you calling pack 6 times? The function
> prototype for pack is "pack TEMPLATE, LIST".
>
> To me, it's much clearer to write:
>
> my $str = pack( "a8 f f f N N",
> $hdr->{id},
> $hdr->{lat},
> $hdr->{lon},
> $hdr->{t},
> $hdr->{nlev},
> $hdr->{flag}, );
Use the slice, Luke:
my $str = pack( "a8 f f f N N",
@$hdr{ qw/ id lat lon t nlev flag/ };
--
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
More information about the Perl
mailing list