On Mon, Aug 15, 2005 at 04:08:22PM -0500, The Ghost wrote: > How can I do this correctly? > > > foreach my $col (@columns) { > my %{$col} = ( # <-- I have a problem here, I want > the hash to be named whatever "$col" is > string => "$col", > number => [EMAIL PROTECTED] > ); > push (@graph, \%{$col}); > } > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > >
Even if you did generate hash names on the fly (which is not a very good idea) you still have no benefit whatsoever. After creating %{$col} you use the reference to it, which effectively destroys the information about the variable name (a reference is a pointer to an in memory structure, be it hash, array or something else, not to a variable name). Then on the next foreach %{$col} falls out of scope and is effectively reinstated as a brand new hash. In other words the above is equivalent to: foreach my $col (@columns) { push (@graph, { string => $col, <-- no need for quotes number => [EMAIL PROTECTED] <-- where did this come from? } ); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>