Hi all!
I'm just beginning to learn Perl.
I'm doing some exercise and I found a problem with subroutines and references.
My question is:
Why in the following simple code I'm not able to obtain the value of the numbers increased of 1?
I did the same sending only a value (a scalar instead of an array) and it worked... ?!?
Thanks in advance, any help will be really appreciated!
Livio.
I'm just beginning to learn Perl.
I'm doing some exercise and I found a problem with subroutines and references.
My question is:
Why in the following simple code I'm not able to obtain the value of the numbers increased of 1?
Code:
#!/usr/bin/perl
# I send the array’s reference to the subroutine
sub incr_ref {
my $aref = shift;
my @rnum = @$aref;
for $i(0..2) {
$$rnum[$i]++;
$i++;
}
}
print "insert 3 numbers to increment of 1: ";
for $i(0..2) {
$mynumber[$i] = <STDIN>;
$i++;
}
incr_ref (\@mynumber);
for $i(0..2) {
print "well, the number increased of 1 now values: $mynumber[$i]\n";
}
I did the same sending only a value (a scalar instead of an array) and it worked... ?!?
Thanks in advance, any help will be really appreciated!
Livio.