Link to home
Start Free TrialLog in
Avatar of tel2
tel2Flag for New Zealand

asked on

Multi pattern match

UNIX has a "-E" switch to allow its grep utility to match multiple patterns at once, eg:
  grep -E "abc|def|ghi|jkl" infile
will match all lines in infile which contain "abc" or "def", etc.

I know Perl has a "grep" command, and I know it can also do pattern matching with the "=~" operator, but how can I write CONCISE Perl code to match multiple patterns with the:
1. grep command?
2. "=~" operator?

Thanks.
Avatar of ozo
ozo
Flag of United States of America image

print grep /abc|def|ghi|jkl/ <>;
print grep /abc|def|ghi|jkl/,<>;
Avatar of tel2

ASKER

ozo,

Is this an answer to both questions, or just #1?  If just #1, are there any other commands (eg: "=~") which allow for multiple pattern matching, if so, please give examples.

What does the "<>" mean exactly?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tel2

ASKER

ozo,

Thanks for that.
So, are you saying that "<>" is the same as "readline"?