in reply to (x == 3 && x != 3)

Sub of is returning a list into a scalar context. That gives you the length of the list, not the first element as you seem to want.

Also, @y = map { $_-1 if mumble } @_ gives you a list that contains undefs where mumble is false. That means $#y is always equal to $#_.

Update: Thanks for the correction, Randal. I had to read it a couple of times, but you're exactly right, of course.

Replies are listed 'Best First'.
•Re: Re: (x == 3 && x != 3)
by merlyn (Sage) on Mar 11, 2002 at 23:42 UTC
    Sub of is returning a list into a scalar context. That gives you the length of the list, not the first element as you seem to want.
    There's no such thing as "returning a list into a scalar context". It's that sort of sloppy language that perpetuates the myth that such a beast can exist. What's actually happening is that you're using map in a scalar context, which counts the number of result elements, and returns that count. At no point was it ever just a list. "map in a scalar context" could be defined instead as "invoke nethack".

    -- Randal L. Schwartz, Perl hacker

Re: Re: (x == 3 && x != 3)
by duelafn (Parson) on Mar 11, 2002 at 22:33 UTC
    Ah yes, I am quite foolish. (hangs his head in shame -- it is sad what silly things get missed)

    Thanks also for the map warning, I'll fix that too.

    Thanks
        -Dean