fork(1) download
  1. #!/usr/bin/perl
  2. # your code goes here
  3.  
  4. %hash = (a=>1,b=>2, c=>3, d=>4);
  5. @arr = ();
  6. foreach(keys %hash) {
  7. # Making a hash
  8. my %temp = ('key' => $_, 'value' => $hash{$_});
  9.  
  10. # Getting its reference
  11. $hashref = \%temp;
  12.  
  13. # Push the reference of hash in the array
  14. push( @arr, $hashref);
  15.  
  16. # Print it to know its value
  17. print $_.' '.$hash{$_}."\n";
  18. }
  19.  
  20. foreach(@arr) {
  21. # Deref the hash
  22. %h = %{$_};
  23.  
  24. foreach(keys %h) {
  25. print 'hash mapkey: '.$_.' mapvalue: '.$h{$_}."\n";
  26. }
  27. print "\n";
  28. }
Success #stdin #stdout 0s 3608KB
stdin
Standard input is empty
stdout
c 3
a 1
b 2
d 4
hash mapkey: value mapvalue: 3
hash mapkey: key mapvalue: c

hash mapkey: value mapvalue: 1
hash mapkey: key mapvalue: a

hash mapkey: value mapvalue: 2
hash mapkey: key mapvalue: b

hash mapkey: value mapvalue: 4
hash mapkey: key mapvalue: d