in reply to Weird grep behaviour

Try grep {$var1 eq $_ } instead.

My guess is that grep uses numerical comparison if called with an EXPR (and not a BLOCK), so "a" == "b".

Replies are listed 'Best First'.
Re^2: Weird grep behaviour
by shmem (Chancellor) on Oct 17, 2007 at 06:08 UTC
    No, it's just that $var1 is "true" for every element in @arr1. There's no comparison in the OP.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: Weird grep behaviour
by naikonta (Curate) on Oct 17, 2007 at 07:36 UTC
    It's not about comparison, BLOCK and EXPR are evaluated in boolean context. From OP's sample code, in grep($var1, @arr1), $var1 is always true.

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!