Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: What is the safest way to find out whether a hash key points to a scalar or a hash reference?

by davis (Vicar)
on Feb 06, 2015 at 15:25 UTC ( [id://1115791]=note: print w/replies, xml ) Need Help??


in reply to What is the safest way to find out whether a hash key points to a scalar or a hash reference?

Try looking at the documentation for the ref function:
#!/usr/bin/perl use warnings; use strict; my %input_data = ( foo => { data => "cheese", }, bar => "scalar", ); foreach my $key (keys(%input_data)) { unless(ref($input_data{$key})) { print "$key isn't a reference, it's just a scalar\n"; } if(ref($input_data{$key}) eq "HASH") { print "$key is a hashref\n"; } elsif(ref($input_data{$key}) eq "SCALAR") { print "$key is a scalar ref\n"; } }

davis

  • Comment on Re: What is the safest way to find out whether a hash key points to a scalar or a hash reference?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-16 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found