Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Get the Keys in the Hash

by vishi83 (Pilgrim)
on Nov 05, 2005 at 15:11 UTC ( [id://505989]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found