in reply to IF NOT! IF NOT!

Grep returns a list, so I'm not sure what the ! will do... you probably either want
unless(grep /home/, @words) { print $words[$x]; }
Your problem is you need to pass grep an array @words, not part of the array $words[$x]... if $words[$x] contains a sub array you need to dereference it like... @{$words[$x]}

It would help if you said a little more about what the data is

Update Nevermind... from other people responses I see what is going on... yeah, you probably want

print $words[$x] if $words[$x] =~ /home/;
oops :)

                - Ant

Replies are listed 'Best First'.
Re: Re: font color="#ff0000"IF NOT! IF NOT!/font
by dragonchild (Archbishop) on Aug 02, 2001 at 22:56 UTC
    As an aside, the construct ! grep EXPR, LIST is used in a boolean context. Either grep returns a list or it doesn't. ! evaluates in a boolean context. A list is TRUE and no list is FALSE.

    I've used it a lot in extended EXPR's, so that I don't have to work through the negation of my && or || that sending if to unless (or vice-versa) would do.

    --------
    /me wants to be the brightest bulb in the chandelier!

      As an aside, the construct ! grep EXPR, LIST is used in a boolean context. Either grep returns a list or it doesn't. ! evaluates in a boolean context. A list is TRUE and no list is FALSE.
      Not the best way to put it, IMHO ... to clarify: in scalar context grep returns the number of times it matched. So if it didn't match anything, it returns 0 which evaluates to false. Otherwise it returns a positive number which evaluates to true.

      The boolean context is enforced by the if (and by the !), so that the grep in if (grep /blah/, @array)also evaluates in boolean context.

      -- Hofmator

        Is it that grep returns a number when evaluated in a scalar context or that grep returns a list which, when evaluated in scalar context, gives the number of matches?

        I know it sounds like a semantic difference, but I'm just curious.

        ------
        /me wants to be the brightest bulb in the chandelier!

      Ahhh... I wasn't sure... the code had me a bit confused anyway... backwards logic does that :)

                      - Ant