vishi83 has asked for the wisdom of the Perl Monks concerning the following question:

hi great ppl !!1

Look this,
$VAR1 = { 'id' => { 'Extra' => 'auto_increment', 'Type' => 'int(11)', 'Field' => 'id', 'Default' => undef, 'Null' => '', 'Key' => 'PRI' }, 'name' => { 'Extra' => '', 'Type' => 'varchar(50)', 'Field' => 'name', 'Default' => '', 'Null' => '', 'Key' => 'UNI' } };

It must be clear that i'm printing this hash ref with a dumper ..

I dint give my code, coz i hav used lot of my own modules in that .. so thot it would be little confusing to all ...


I hav generated this hash from a db table ...For this i have written a method ('fetchit')...
this method is used like this..

$hashref = $object->fetchit($tablename);
so this method will return the table desc as a hash..

NOw i got struck in one thing.. please help me in this.. I want to print only the FIELD names present inside that hash.. here the field names are id and name ..

How can i do that ??? .. please help me

Thanks in advance

A perl Script without 'strict' is like a House without Roof; Both are not Safe;

Replies are listed 'Best First'.
Re: Get the Keys in the Hash
by Corion (Patriarch) on Nov 05, 2005 at 15:36 UTC

    tyes References Quick Reference will likely be of help and will explain to you how to handle the references. In short:

    keys %{ $hashref }

    will give you all keys in your hash(reference).

Re: Get the Keys in the Hash
by Trix606 (Monk) on Nov 05, 2005 at 15:18 UTC
    If you want the keys to a hash, use

    keys %my_hash

    Look at perldoc -f keys for the details.