Hello friend!

welcome to w0xy's Perl Web Environment


subroutine code (pastebin):


#this is the data structure we are inserting into the subroutine, it is an array containing several lists, hashes, and values
$structure
= [ { a => 1, b => 2, c => 3 }, { d => 4, e => 5 }, [ 6, 7, 8 ], 9, 10, 11, [ 12, 13, 14 ] ];

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;
}

what the subroutine should return: [ { a => 3, b => 4, c => 5 }, { d => 6, e => 7 }, [ 8, 9, 10 ], 11, 12, 13, [ 14, 15, 16 ] ]


what the subroutine actually returns:



The initial $structure has the type: ARRAY
HASH(0x1ca1b78)
HASH(0x1cc20f8)
ARRAY(0x1ca1ae8)ARRAY(0x1ca1ae8)ARRAY(0x1ca1ae8)ARRAY(0x1ca1ae8)
9
10
11
ARRAY(0x1cc2128)ARRAY(0x1cc2128)ARRAY(0x1cc2128)ARRAY(0x1cc2128)
structure in text form [ { a => 1, b => 2, c => 3 }, { d => 4, e => 5 }, [ 6, 7, 8 ], 9, 10, 11, [ 12, 13, 14 ] ]
structure length: 7

First array item is:
Second array item is:
Third array item is:
Fourth array item is:
Fifth array item is:
Sixth array item is:
Seventh array item is:
HASH(0x1ca1b78)
HASH(0x1cc20f8)
ARRAY(0x1ca1ae8)
9
10
11
ARRAY(0x1cc2128)