Determining if reference $ref is a Hash

Discussion in 'Perl Misc' started by Michaelp, Aug 4, 2009.

  1. Michaelp

    Michaelp Guest

    Hello!

    How do I cleanly determine if $ref refers to a hash?

    To be used like:
    if (isHash ($ref)){
    # traverse the hash
    }

    Thanks

    Michael
    Michaelp, Aug 4, 2009
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Michaelp wrote:
    > Hello!
    >
    > How do I cleanly determine if $ref refers to a hash?
    >
    > To be used like:
    > if (isHash ($ref)){
    > # traverse the hash
    > }
    >
    > Thanks
    >
    > Michael


    Hello,

    I did not tested this, but this could help:

    http://www.perlmonks.org/?node_id=32129


    PS: the google search termn was: "perl check if hash"

    regards,
    johannes keßler
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.11 (GNU/Linux)

    iEYEARECAAYFAkp4AcsACgkQE++2Zdc7EtfQGgCfc6jx1LOBLL83cVwtzCETV+Cf
    /50AnjQbaSMyQC+S4gAj/UqCvviW949m
    =oMOb
    -----END PGP SIGNATURE-----
    johannes keßler, Aug 4, 2009
    #2
    1. Advertising

  3. On 04 Aug 2009 Michaelp <> wrote in news:200ea0e8-4a75-
    :

    > Hello!
    >
    > How do I cleanly determine if $ref refers to a hash?
    >
    > To be used like:
    > if (isHash ($ref)){
    > # traverse the hash
    >}


    perldoc -f ref

    if (ref($ref) eq "HASH") {

    --
    Graham Drabble
    http://www.drabble.me.uk/
    Graham Drabble, Aug 4, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    330
  2. Replies:
    22
    Views:
    739
    peter koch
    Apr 30, 2008
  3. rp
    Replies:
    1
    Views:
    493
    red floyd
    Nov 10, 2011
  4. Rg

    Hash vs. Hash ref

    Rg, May 3, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    88
    Paul Lalli
    May 3, 2007
  5. Justin C
    Replies:
    1
    Views:
    177
    Justin C
    Oct 7, 2013
Loading...

Share This Page