[Chicago-talk] print keys for anon hash

Kearney, Tim tkearney at fastweb.com
Mon Dec 15 09:50:55 CST 2003


# for the first anonymous hash
foreach my $key (keys %{$crew[0]}) {
  print "found $key\n";
}

# for the second anonymous hash
foreach my $key (keys %{$crew[1]}) {
  print "found $key\n";
}

# etc.


-- Tim


-----Original Message-----
From: Dooley, Michael [mailto:Dooley.Michael at con-way.com]
Sent: Monday, December 15, 2003 9:44 AM
To: Chicago.pm chatter
Subject: [Chicago-talk] print keys for anon hash


How do I print out the keys for a specific anon hash?

if I say print $crew[0]{'name'},"\n"; I can get the name of a specific key
but what if I wanted all the keys for that anon hash?

am I missing something?

#!/usr/bin/perl -w
use strict;
my @crew = (
        {
                name => 'Gilligan',
                hat => 'White',
                shirt=>'red',
                position=>'first mate',
        },
        {
                name => 'Skipper',
                hat => 'Black',
                shirt=>'Blue',
                position=>'Captain',
        },
);

print keys ($crew[0]),"\n";

[qgatu003]/export/home/mxdooley/perl_objects_references_modules/chap04$./tes
t.pl
Type of arg 1 to keys must be hash (not array element) at ./test.pl line 20,
near "])"
Execution of ./test.pl aborted due to compilation errors.

Mike
_______________________________________________
Chicago-talk mailing list
Chicago-talk at mail.pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk


"Bringing people together to advance their lives." 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20031215/b1c39f61/attachment.htm


More information about the Chicago-talk mailing list