Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
"be consistent"

Re: Re: defined array question

by toadi (Chaplain)
on Aug 30, 2002 at 11:27 UTC ( #194066=note: print w/ replies, xml ) Need Help??

in reply to Re: defined array question
in thread defined array question

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

Comment on Re: Re: defined array question
Re: Re: Re: defined array question
by BrowserUk (Pope) on Aug 30, 2002 at 12:16 UTC

    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> 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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194066]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-04-16 16:55 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (433 votes), past polls