in reply to defined array question

Your right! That doesn't make much sense. Either you have a bad installation on one machine, or there is something going on in your script that you aren't telling us.

Like, what error did you get that caused you to change it?

If you would post the (appropriate part of, if big) script, along with the exact error message (cut&paste rather than copy)-- don't forget to indicate which line of the code your post is the line referred to in the error message--we might be able to help you further.


Well It's better than the Abottoire, but Yorkshire!

Replies are listed 'Best First'.
Re: Re: defined array question
by toadi (Chaplain) on Aug 30, 2002 at 11:27 UTC
    I do a fetchrow from a db to fill tha array. The script generates no errors!!!! It just doesn't get into the if!!!!

    --
    My opinions may have changed,
    but not the fact that I am right

      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.


      Well It's better than the Abottoire, but Yorkshire!