Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to correctly use a symbolic reference to automatically generate hash names?

by runrig (Abbot)
on Mar 04, 2014 at 21:30 UTC ( [id://1076967]=note: print w/replies, xml ) Need Help??


in reply to How to correctly use a symbolic reference to automatically generate hash names?

No. Have one hasharray of lists of lists hashes (NOT multiple hashes), and do, e.g.:
my @wow; ... push @{$wow[$i]{$row[$i]}}, "sth";
  • Comment on Re: How to correctly use a symbolic reference to automatically generate hash names?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to correctly use a symbolic reference to automatically generate hash names?
by lightoverhead (Pilgrim) on Mar 04, 2014 at 21:36 UTC

    Thank you for your reply.

    However, what I have is a set of hashes such as %wow0, %wow1,%wow2, %wow3, .... That's why I want to use a loop to handle these hashes and I need an automatic way to refer to these hashes and to update info on these hashes.

      Why on earth would you have %wow1, %wow2, and %wow3, instead of %{$wow[1]}, %{$wow[2]}, and %{$wow[3]}? In other words, instead of:

      %wow1 = ( key => value, key => value ); %wow2 = ( key => value, key => value );

      You could have...

      @wow = ( { key => value, key => value }, { key => value, key => value }, );

      Which is an array of hashes, instead of a bunch of hashes loosely related by naming convention.

      I see no advantage to polluting your package global namespace with variable names that are tricky to manipulate when you could just create a single AoH structure.


      Dave

      I am suggesting to not have a set of hashes named %wow0, %wow1, etc., and to instead do as I have suggested.

        you seemed suggesting to put the names of the hashes in an array then refer them the way you posted.

        is there a way to refer to hashes as I original wanted?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1076967]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found