Grep Help
am 16.11.2007 06:56:10 von M
Normally this would search an array for a given string:
if (grep /^X-Spam-Flag: YES/, @data)
Instead of searching for "X-Spam-Flag: YES" I want to search for
"X-Spam-Level: **********". Meaning a message has scored 10 spam points.
How do I make that work? It seems to choke due to the * character.
M
Re: Grep Help
am 16.11.2007 07:30:10 von Peter Makholm
"M" writes:
> if (grep /^X-Spam-Flag: YES/, @data)
>
> Instead of searching for "X-Spam-Flag: YES" I want to search for
> "X-Spam-Level: **********". Meaning a message has scored 10 spam points.
> How do I make that work? It seems to choke due to the * character.
You question seems to be how to match to stars in a regular
expression. As stars have a special meanig in regular expressions
you'lll have to escape them:
/X-Spam-Level: \*\*\*\*\*\*\*\*\*\*/
or better
/X-Spam-Level: \*{10}/
//Makholm
Re: Grep Help
am 16.11.2007 09:03:19 von Ron Bergin
On Nov 15, 9:56 pm, "M" wrote:
> Normally this would search an array for a given string:
>
> if (grep /^X-Spam-Flag: YES/, @data)
>
> Instead of searching for "X-Spam-Flag: YES" I want to search for
> "X-Spam-Level: **********". Meaning a message has scored 10 spam points.
> How do I make that work? It seems to choke due to the * character.
>
> M
/^X-Spam-Level: \*{10}/
Re: Grep Help
am 16.11.2007 12:53:31 von Tad McClellan
M wrote:
> Normally this would search an array for a given string:
>
> if (grep /^X-Spam-Flag: YES/, @data)
>
> Instead of searching for "X-Spam-Flag: YES" I want to search for
> "X-Spam-Level: **********". Meaning a message has scored 10 spam points.
> How do I make that work? It seems to choke due to the * character.
if (grep /^\QX-Spam-Flag: **********/, @data)
see also:
perldoc -f quotemeta
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Re: Grep Help
am 19.11.2007 13:06:23 von rvtol+news
M schreef:
> if (grep /^X-Spam-Flag: YES/, @data)
Actually a pity that Perl doesn't have boolean context, which could make
that grep to short circuit.
See also List::Util::first().
--
Affijn, Ruud
"Gewoon is een tijger."