in reply to Re: Re: defined array question
in thread defined array question
In the absence of further info, I'd have to suspect a bad build then.
Looking at this further, I am a bit confused as to what the if line does anyway. When I saw it, I thought it was a smart way to test all the values in @user_geg for definedness, but I just ran the following script:
#! perl -w use strict; my @test = ( 0,1,2,3,4,5,6,7,8,9); print 'OK'.$/ if defined( @test[0 .. $#test] ); $test[5] = undef; print 'OK'.$/ if defined( @test[0 .. $#test] ); @test[0 .. $#test] = (undef, undef, undef, undef, undef, undef, undef, + undef, undef, 1); print 'OK'.$/ if defined( @test[0 .. $#test] ); $test[$#test] = undef; print 'OK'.$/ if defined( @test[0 .. $#test] ); __END__ # Output C:\test>test.pl OK OK OK C:\test>
But as you can see, the only value being tested is the last value. Which makes sense as an array slice is just a list, and a list in a scalar context is just its last value. Which means that the test is equivalent to
if ( $user_geg[$#user_geg] ) {...}
That means that your change to $#user_geg-1 is testing the last but one value, which strongly suggests that the last value is undefined?
My only suggestion is to preceed the if with print defined $user_geg[27]; and see what you get? But if you are seeing output from print $user_geg[27];, it should be defined!
Sorry I can't suggest better.
|
|---|