in reply to Re^5: trying to decide best data structure for problem at hand.
in thread trying to decide best data structure for problem at hand.

Ok thik I am getting this a little more. I printed it using Dumper like so:
print Dumper(\%entries),"\n"; which produces 'kloesch' => { '291' => { 'gecos' => '', 'host' => '/home/dbsmith/passwd.sp +sdbp.hpux', 'gid' => '102' } }, 'sapdp4' => { '484' => { 'gecos' => '', 'host' => '/home/dbsmith/passwd.dud +bdv02.aix', 'gid' => '208' } },
I have been banging my head at how to get at gecos and gid and uid in the right printed format. The output I would like it is:
wlprdadm => uid #s, gid and gecos found on /home/dbsmith/passwd.eipdbmp1.hpux /home/dbsmith/passwd.carappp1.hpux but of course being uid, gid and gecos actual values. Finally, can a hash only contain keys like so: my %hash; my array= (a..d); $hash{$_}++ foreach @array;
thank you

Replies are listed 'Best First'.
Re^7: trying to decide best data structure for problem at hand.
by GrandFather (Saint) on Jan 08, 2007 at 20:48 UTC

    I think the best help I can give you at this point is to send you back to school. ;)

    Take a wander around the Tutorials campus, especially check out the Data Types and Variables department. The Data Type: Hash courses will be of particular interest. You will find the texts perldata, perlref and perldsc are required reading for those courses.

    Enjoy your term back at school.


    DWIM is Perl's answer to Gödel
      yeah...i do need to understand hashes better b/c I do not seem to get them, but I got it working:
      for my $i ( keys %dub_hash ) { my $key = "$i -- "; if (keys (%{$dub_hash{$i}}) > 1) { print $key, join( "\n" . ' ' x length $key, keys %{ $dub_hash{ $i } } ),"\n"; } }
      thanks again.
      ##-- Create a HoHoH. 1st hash keyed by name, that accesses 2nd hash k +eyed by UID, that accesses 3rd hash keyed by remaining items: gid,gec +os and hostname --## $dub_hash{$name}{$uid} = { # User data keyed by uid gid => $gid, gecos => $gecos, host => $host,
      So this code creating 3 hashes one with a key of name and the next with a key of uid and gid, gecos and host are values in the last hash? thank you

        Yes. dub_hash is a hash. {$name} accesses an element in the hash, creating it if it didn't exist already.

        {$name}{$uid} is shorthand for {$name}->{$uid} which implies the value accessed by $name is a hash reference. Again the hash element is generated if it didn't exist already.

         = {...}; is an annonymous hash whose reference is assigned to the element accessed by {$name}{$uid}.

        The result is a HoHoH - hash of hash of hash.


        DWIM is Perl's answer to Gödel