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  => '$'

};

...

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{$x}->name($temp1);
$carriers{$x}->abbrev($temp2);
$carriers[$x]->name($temp1);
$carriers[$x]->abbrev($temp2);
Where $x is an incrementing counter and the temp variables are my data I
am trying to load.

Hey Travis.

I assume you are using the Class::Struct module? It would have been good to
say so as there are thousands of Perl modules out there and it can be hard
to guess from a code sample which one is being used.

How many carriers do you want in your array? This piece of code pushes
10 carriers into your array and names the first three. I hope it helps.

Rob


use strict;
use warnings;

use Class::Struct;

struct Carrier_Info => {
 name    => '$',
 abbrev  => '$'
};

my @carriers;

push @carriers, Carrier_Info->new for 1 .. 10;

$carriers[0]->name('C1');
$carriers[1]->name('C2');
$carriers[2]->name('C3');

print $_->name, "\n" foreach @carriers[0..2];


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to