in reply to Re: perl if statement
in thread perl if statement

Hi Laurent, You are right.. I am thinking more of shell script grep. what ways can I get this done in Perl.. any help appreciated.

Replies are listed 'Best First'.
Re^3: perl if statement
by Laurent_R (Canon) on Feb 29, 2016 at 20:54 UTC
    Well, for changing as little as possible to your code, you could slurp the content of the file into an array and then use your grep function on that array.

    One quick and simple possibility is as follows:

    my $infile = "/export/install/users.txt"; open my $IN, "<", $infile or die "Cannot open $infile $!"; my @lines = <$IN>; if (grep /($FORM{user}|$FORM{pin})/i, @lines) { # ... }
      Hi Laurent, Many thanks, it worked. The only issue is that the grep:  grep /($FORM{user}|$FORM{pin})/i only matches the first condition even when both conditions are on the same line.

        see Alternation

        Try
        grep /($FORM{user}\|$FORM{pin})/i
                          ^ add \
        
Re^3: perl if statement
by FreeBeerReekingMonk (Deacon) on Feb 29, 2016 at 22:01 UTC