> -----Message d'origine-----
> De : Randy W. Sims [mailto:[EMAIL PROTECTED]
> Envoyé : samedi 7 août 2004 02:50
> À : [EMAIL PROTECTED]
> Cc : [EMAIL PROTECTED]
> Objet : Re: iterate over the fields of a struct?
> 
> Christopher J. Bottaro wrote:
> > is there a way to iterate over the fields of a Class::Struct (in the
> order
> > they were declared)?
> 
> No. You could store the data used to generate the struct, and then use
> it later.
> 
> my @struct_data = [
>    key1 => 'type',
>    key2 => 'type',
> ];
> 
> struct Name => [EMAIL PROTECTED];
> 
> then iterate of @struct_data...
> 

did you meant:

my $struct_data = [ #array_ref
    key1 => 'type',
    key2 => 'type',
];

struct Name => $struct_data;
then iterate of @$struct_data ...

?

array = array_ref is confusing to me ...
could you explain please ?

> >
> > yeah i know its a long shot, but perl sometimes does things for me
that
> i
> > never would have believed...much less knew to expect...;)
> >
> > also, i know you can do this with hashes (although in "random"
order,
> unless
> > you sort the keys), but hashes are too error prone for my liking.
i.e.
> > $my_hash{TYPO} = $blah; does not result in an error...=(
> 
> If you're using version 5.8 or later you can use restricted hashes.
See
> `perldoc Hash::Util`
> 

helpfull module !
Hash vivification is a nightmare, really ...

José.


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


Reply via email to