Re: iterate over the fields of a struct?

2004-08-09 Thread Christopher J. Bottaro
Randy W. Sims wrote:
> If you're using version 5.8 or later you can use restricted hashes. See
> `perldoc Hash::Util`

heh, that was exactly what i'm looking for, thanks.  ugh, now i gotta
rewrite 3 days worth of code with restricted hashes instead of
Class::Struct ...=/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE : iterate over the fields of a struct?

2004-08-07 Thread Jose Nyimi


> -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>




Re: iterate over the fields of a struct?

2004-08-07 Thread Randy W. Sims
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...
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`

Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



iterate over the fields of a struct?

2004-08-06 Thread Christopher J. Bottaro
is there a way to iterate over the fields of a Class::Struct (in the order
they were declared)?

something like:

foreach my $i (@{my_struct->fields()})  {
print "$i = my_struct->value($i)\n";
}

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...=(

thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]