[Chicago-talk] print keys for anon hash

Dooley, Michael Dooley.Michael at con-way.com
Mon Dec 15 09:44:07 CST 2003


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



More information about the Chicago-talk mailing list