fork download
  1. print addtwo();
  2. sub addtwo {
  3.  
  4. my $params = shift;
  5.  
  6. my $s = $params->{STRUCTURE}; # ; was missing at the end of a line
  7. print 1;
  8. #
  9. if (ref($s) eq "LIST") {
  10. $c = 0;
  11. foreach $e (@{$s}) {
  12. print $c;
  13. $s->[$c] = addtwo({ structures => $e });
  14. $c++; # to increment $c we need to use double plus sign "++"
  15. }
  16.  
  17. #
  18. } elsif (ref($s) eq "HASH") {
  19.  
  20. if (scalar keys %{$s} == 0) {
  21. } else {
  22. foreach my $e (values %{$s}) {
  23. $s{$e} = addtwo({ structure => $s->{$e} });
  24. }
  25. }
  26.  
  27. } else {
  28. $s = 1;
  29. }
  30.  
  31. return $c;
  32.  
  33. }
  34.  
Success #stdin #stdout 0s 4328KB
stdin
[{a=>1,b=>2,c=>3},{d=>4,e=>5},[6,7,8],9,10,11,[12,13,14]]
stdout
1