in reply to Data structure for this...
As far as using a datastructure, a hash makes the most sense since trying to remember which array index corresponds to which variable is a PITA. This will also allow you to create complex data structures (AoH, HoH, etc) later if you need to.my ($one, $two, $three) = qw(1 2 3); # works just fine
There are two more things to point out. The first is that it appears you have more variables than the unpack will return - which means undef values. The second is to understand auto-vivication when using hash slices.#!/usr/bin/perl -w use strict; my $buffer; # Defined elsewhere my %hash; my @keys = qw(flags x y mode3 callsign route spare1 spare2 flight_leve +l); @hash{@keys} = unpack ( "B16 n2 A4 A8 A2 A A A3 C2" }, $buffer); print $hash{mode3};
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Data structure for this...
by robinbowes (Beadle) on Oct 16, 2003 at 16:22 UTC | |
by Limbic~Region (Chancellor) on Oct 16, 2003 at 16:39 UTC | |
by dragonchild (Archbishop) on Oct 16, 2003 at 16:40 UTC |