title: Perl Array References and avoiding "Type of arg 1 to keys must be hash" error
body: <p>I have a scalar <code>$subscribers</code> that could be undef, reference to a HASH, or reference to an ARRAY. I have assigned the sample values <code>$VAR1</code>, <code>$VAR2</code> and <code>$VAR3</code> for testing.</p>
  
  <p>I'm only interested in <code>$subscribers</code> when it is a reference to an ARRAY, where by it would contain multiple values. In other cases, I'm not interested in printing anything (e.g. when <code>$subscribers=$VAR2;</code></p>
  
  <p>The code seems to run fine under Perl v5.16.2; however, when I move it to the target machine running <strong>Perl v5.8.8, I get a compile error</strong>:</p>
  
  <pre class="lang-sh prettyprint-override"><code>% ./test.pl
  Type of arg 1 to keys must be hash (not private variable) at ./test.pl line 23, near "$subscribers) "
  Execution of ./test.pl aborted due to compilation errors.
  </code></pre>
  
  <p>Code below:</p>
  
  <pre class="lang-perl prettyprint-override"><code>#!/usr/bin/perl -w
  
  use strict;
  use warnings;
  use Data::Dumper;
  
  my $VAR1 = undef;
  
  my $VAR2 = {'msisdn' =&gt; '1234'};
  
  my $VAR3 = [
    {'msisdn' =&gt; '1111'},
    {'msisdn' =&gt; '2222'},
    {'msisdn' =&gt; '3333'},
    {'msisdn' =&gt; '4444'},
    {'msisdn' =&gt; '5555'}
  ];
  
  my @childMsisdn = ();
  my $subscribers = $VAR3;
  
  if (ref $subscribers eq ref []) { # Exclude $VAR1 &amp;&amp; $VAR2 scenarios
    foreach my $s (keys $subscribers) {
      my $msisdn = $subscribers-&gt;[$s]-&gt;{"msisdn"};
      push (@childMsisdn, $msisdn);
    }
  }
  print "childMsisdn = ". join(",", @childMsisdn) ."\n";
  </code></pre>