Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Hash of Arrays or Arrays of arrays? and how proceed?

by paride (Initiate)
on Aug 03, 2011 at 08:42 UTC ( [id://918204]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Hash of Arrays or Arrays of arrays? and how proceed?
in thread Hash of Arrays or Arrays of arrays? and how proceed?

now all work ....but I realized I need a more complex solution... :(

I've transformed $nextfield in an array because of two different DB could have 1 ore more fields less than the other one, and the result is OK! printing Dumper (when @Database is ("5","6"):

$VAR1 = \'6'; $VAR2 = 'AP', 'AO' ; $VAR3 = 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN' ;

But to proceed correctly I need a different @fields($VAR3) for every database, and to reach the top of my desired target I would like to add other attributes to the sigle field. For example AA,5(dimension),N(numeric) etc.

I know it's very complex jethro, when I start with the idea to do this script I didn't expect it will be so complex. But I think this could be an excellent way to learn perl in dept

  • Comment on Re^4: Hash of Arrays or Arrays of arrays? and how proceed?

Replies are listed 'Best First'.
Re^5: Hash of Arrays or Arrays of arrays? and how proceed?
by jethro (Monsignor) on Aug 03, 2011 at 10:12 UTC

    Oh yes, you will be an expert on references and complex data structures after this ;-)

    One advice: You could store your attributes (i.e. AA, 5 'N' etc.) in strings (concatenated by ':' for example) or in arrays (i.e. index 0 would be 'AA', index 1 the dimension...). But usually the most maintainable way to do this is with a hash.

    #add values $fields{$database}[$fieldno]{dimension}=5; $fields{$database}[$fieldno]{type}='N'; # check if an attribute 'something' exists if (exists $fields{$database}[$fieldno]{something}) {

      Thanks, I've choosen the string solution (AA,5,N...) and it work perfectly, but if I need to have a different @fields stored for each database? it works in sub but outside when I do the loop for each $Database to re-print dumper using

      Dumper(\$Database,\@nextfield,\@fields);

      It print only the fields of the "last" $Database acquired... did you have an idea about it?

        ...but if I need to have a different @fields stored for each database?

        Well, I told you the third solution with hashes is the best, because there undefined fields are not a problem at all. With strings you always have to set all fields. You just define the empty string (or a value that is not a valid value) for any field as an empty field. So if for example the dimension is undefined for a database you would have (AA,,N...). But using the empty string is only possible if it is not a valid value anywhere. If that is not the case you would have to use some ugly construct where '@@@' or something means undefined

        It print only the fields of the "last" $Database acquired

        '$Database' is not '$database'. upper/lower case is important.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-20 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found