in reply to Operator precedence (or, I'm an idiot)

Just another reason that grep (or map) in a void context should generate a warning.

I'm also curious why the simple version of your code reports

Found = in conditional, should be ==
but the full version does not.

                - tye

Replies are listed 'Best First'.
Re: Re: Operator precedence (void context)
by rir (Vicar) on Mar 07, 2003 at 22:02 UTC
    With the routine the $var may vary.

    Even with:

    sub rout { &blah; 1; }
    there may be side effects.

      Of course there may be side effects. That is why you don't have to use -w. But there is no good reason to use grep and/or map solely for their side effects and there are good reasons to not do so. The warning would be:

      Use of map/grep in void context, use foreach instead
      If you have some perverse reason for doing such, then just turn off that warning. For people wanting help in catching simple errors, the warning will be useful.

                      - tye
        As to how Perl can be improved. I agree with tye, map and grep should generate a warning in void context. I'd leave out the foreach recommendation except under diagnostics.

        In the same vein, Perl should have a wantvoid or wantbool operator so that the general case can be handled.