in reply to Re: CGI Help
in thread CGI Help

is there a certain situation you shoud use grep in and not to use grep in?

Replies are listed 'Best First'.
Re^3: CGI Help
by kennethk (Abbot) on Feb 10, 2016 at 20:17 UTC
    grep in Perl is essentially a simple method for filtering a list. I tend to recommend avoiding it while you are still familiarizing yourself with Perl's constructs.

    grep allows you to accomplish something like:

    my @second; for my $element (@first) { push @second, $element if condition($element); }
    in a concise syntax. Simple filtering by a regular expression is a classic use case. If you have side effects or complex tests, then grep may be a bad choice.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.