Travis Hervey wrote:
From: John W. Krahn [mailto:[EMAIL PROTECTED]
Travis Hervey wrote:
How do you Create an array of a struct in perl? Is this even possible
in perl?
So far I have...
struct Carrier_Info => {
name => '$',
abbrev => '$'
};
That looks like a hash so:
my %Carrier_Info = (
name => '$',
abbrev => '$',
);
Or:
my $Carrier_Info = {
name => '$',
abbrev => '$',
};
my @carriers = Carrier_Info->new();
I have tried several different methods of loading data into the struct
but none have been successful so far. I've tried:
$carriers{$x} = [$temp1, $temp2];
@carriers is an array so you probably want:
push @carriers, [ $temp1, $temp2 ];
How do you then access the information stored in the individual
elements?
Is it something like:
print $carriers[$x]{'name'}, " | ", $carriers[$x]{'abbrev'}, "\n";
print $carriers[$x][0], " | ", $carriers[$x][1], "\n";
Unless you really want an array of hashes?
perldoc perldata
perldoc perldsc
perldoc perllol
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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/