Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub addtwo {
- #shift the first value from @_, the argument list of the subroutine
- #shift() is a built in Perl subroutine that takes an array as an argument, then returns and
- #deletes the first item in that array.
- my $params = shift;
- #set a variable 's' to be a shift of the $structure variable
- my $s = $params {$structure};
- #if 's' has a datatype of LIST
- if (ref($s) eq "LIST") {
- $c = 0;
- foreach my $e (@{$s}) {
- $s->[$c] = addtwo({ structures => $e });
- #"->" is an infix dereference operator, just as it is in C and C++.
- #If the right side is either a [...], {...}, or a (...) subscript, then the left side
- #must be either a hard or symbolic reference to an array, a hash, or a subroutine
- #respectively. (Or technically speaking, a location capable of holding a hard reference,
- #if it's an array or hash reference being used for assignment.)
- $c++;
- }
- } elsif (ref($s) eq "HASH") {
- if (scalar keys %{$s} == 0) {
- return undef;
- } else {
- foreach my $e (values %{$s}) {
- $s{$e} = addtwo({ structure => $s->{$e} });
- }
- }
- } else {
- $s = 1;
- }
- return $c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement