AntsPants has asked for the wisdom of the Perl Monks concerning the following question:
I have a list, and sometimes I want to read-ahead (next element) in the list and compare it to my current element (while the index stays on my current element)
If there's a next element (i.e. I'm not out of bounds) then I'll grab a value. If there's no next element then I'm done.
This works ..........
but then I thought I'd try ............my $next_version_key = $ordered_list->[($i+1)]->[0] if( $ordered_list->[($i+1)] );
and that added ..........my $next_version_key = $ordered_list->[($i+1)]->[0] || undef;
which meant my list had grown. The next time round, it added ......[] to @{ $ordered_list }
next time round ..............[ undef, {} ]
usw. The same happens if I use ............[ ${\$VAR1->[3][0]}, {} ]
Now, it seems as though $ordered_list->[($i+1)]->[0] is evalutaing to true even though it's out-of-bounds but what strange behaviour!!my $next_version_key = $ordered_list->[($i+1)]->[0] || 0;
Can someone throw some light on that for me? This isn't critical as I'm using ...
which my prefered way .... I'm just interested in the internals with this prob.my $next_version_key = $ordered_list->[($i+1)]->[0] if( $ordered_list->[($i+1)] );
Cheers -Ants
Back to
Seekers of Perl Wisdom