Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.27 KB | None | 0 0
  1. sub addtwo {
  2.         #shift the first value from @_, the argument list of the subroutine
  3.         #shift() is a built in Perl subroutine that takes an array as an argument, then returns and
  4.         #deletes the first item in that array.
  5.     my $params = shift;
  6.         #set a variable 's' to be a shift of the $structure variable
  7.     my $s = $params {$structure};
  8.    
  9.  
  10.     #if 's' has a datatype of LIST
  11.     if (ref($s) eq "LIST") {
  12.          $c = 0;
  13.         foreach my $e (@{$s}) {
  14.             $s->[$c] = addtwo({ structures => $e });
  15.              #"->" is an infix dereference operator, just as it is in C and C++.
  16.          #If the right side is either a [...], {...}, or a (...) subscript, then the left side  
  17.                  #must be either a hard or symbolic reference to an array, a hash, or a subroutine
  18.          #respectively. (Or technically speaking, a location capable of holding a hard reference,
  19.          #if it's an array or hash reference being used for assignment.)
  20.             $c++;
  21.         }
  22.     } elsif (ref($s) eq "HASH") {
  23.  
  24.         if (scalar keys %{$s} == 0) {
  25.             return undef;
  26.        } else {
  27.             foreach my $e (values %{$s}) {
  28.                 $s{$e} = addtwo({ structure => $s->{$e} });
  29.             }
  30.         }
  31.    
  32.     } else {
  33.         $s = 1;
  34.     }
  35.  
  36.     return $c;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement