[Israel.pm] pack vs. different architectures
Shlomi Fish
shlomif at iglu.org.il
Tue Feb 22 06:10:45 PST 2005
On Tuesday 22 February 2005 13:13, Gaal Yahas wrote:
> On Tue, Feb 22, 2005 at 12:01:36PM +0200, Gaal Yahas wrote:
> > Use the slice, Luke:
> >
> > my $str = pack( "a8 f f f N N",
> > @$hdr{ qw/ id lat lon t nlev flag/ };
>
> Or, if you do this kind of thing a lot, this is a nice place to use
> order-preserving hashes.
>
> our $header_template = Tie::IxHash->new(
> id => 'a8',
> lat => 'f',
> lon => 'f',
> t => 'f',
> nlev => 'N',
> flag => 'N',
> );
>
> sub struct_packer {
> my($template, $data) = @_;
>
> # could be made better, no doubt.
> die "template and data mismatch" if $template->Length != $data;
>
> pack join("", $t->Values), $data->{ $t->Keys };
You probably mean @{$data}{$t->Keys} here. And $template instead of $t.
And I don't see the advantage of having an order preserving hash instead of
having an array, with each element containing both the $hdr key and its
appropriate pack time.
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif at iglu.org.il
Homepage: http://www.shlomifish.org/
Knuth is not God! It took him two days to build the Roman Empire.
More information about the Perl
mailing list