[EMAIL PROTECTED] wrote:
Well simple if you are not learning Perl. You guessed it, I am a
newbie.
My question is if I have an array like this, actually it is my whole
program.
my @testarray=( [5, [1,3,18,21]], [16, [1,2,3]], [21, [1]]);
print [EMAIL PROTECTED];
print [EMAIL PROTECTED];
print [EMAIL PROTECTED];
What I had expected and what I want is to print out 4, 3, and 1 but it
prints out 1 and 1 and I don't know why.
$ perl -MO=Deparse -le'
my @testarray = (
[ 5, [ 1, 3, 18, 21 ] ],
[ 16, [ 1, 2, 3 ] ],
[ 21, [ 1 ] ],
);
print [EMAIL PROTECTED] 0 ][ 1 ];
print [EMAIL PROTECTED] 1 ][ 1 ];
print [EMAIL PROTECTED] 2 ][ 1 ];
'
BEGIN { $/ = "\n"; $\ = "\n"; }
my(@testarray) = ([5, [1, 3, 18, 21]], [16, [1, 2, 3]], [21, [1]]);
print print(print($_));
-e syntax OK
The # character signifies the beginning of a comment so everything after
it is ignored and thus you get "print print(print($_));" where "1" is
what is returned from print()
The 4,3, and 1 are the
lengths of the second array in the array of arrays.
What you look like you where trying to accomplish is:
print $#{ $testarray[ 0 ][ 1 ] };
print $#{ $testarray[ 1 ][ 1 ] };
print $#{ $testarray[ 2 ][ 1 ] };
But that doesn't print the lengths of the arrays, for that you need:
print scalar @{ $testarray[ 0 ][ 1 ] };
print scalar @{ $testarray[ 1 ][ 1 ] };
print scalar @{ $testarray[ 2 ][ 1 ] };
If someone could put me right I can move on (to the next problem and
understanding your code).
perldoc perldata
perldoc perldsc
perldoc perllol
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/