Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Is this a reasonable data structure?

by tadman (Prior)
on Oct 23, 2003 at 20:32 UTC ( [id://301705]=note: print w/replies, xml ) Need Help??


in reply to Is this a reasonable data structure?

Keep in mind that your assignment is totally broken. Missing equals sign aside, see what this does:
my @array = (%hash1, %hash2);
What you end up with is merely a list of the key/value pairs from %hash1 and %hash2, not an array of hashes.

As hardburn suggested, what you want is a hash of hashes (HoH):
use warnings; use strict; my @template; my %data; while (<>) { chomp; my @line = split(/\|/, $_); if (!@template) { @template = @line; } else { my $key = lc($line[2]."_".substr($line[1],0,1)); @{$data{$key}}{@template} = @line; } } use Data::Dumper; print Dumper(\%data);
I really have no idea how you were going to name your hashes like that, so I guessed. Note that you might have to fix the $key definition so that two "B.Smith" people don't collide.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found