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

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) { # ... }

Replies are listed 'Best First'.
Re^4: perl if statement
by Drsin (Novice) on Mar 01, 2016 at 14:06 UTC
    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 \
      

        More likely /(\Q$FORM{user}|$FORM{pin}\E)/i is better!