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