in reply to Fell off the Llama

It can be hard to focus on things when you've been through a lot of emotional events, so you might just need a little more time before you climb back on. But if you feel like you're really ready, here's as good a job as I can do to make the exercise even more clear.

The exercise is dealing with regular expressions (which the book is calling patterns), which are a kind of string-description language.

The Perl operator for applying a regular expression to a string to see if it matches, is the "match operator", m//. The m is optional (and generally omitted) if slashes are used. The regular expression goes between the slashes. To see if $_ matches $pattern, we just do /$pattern/.

To see if the pattern in $what appears somewhere in $_ three times in a row, we can do /$what$what$what/, or /($what){3}/ for short.


We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^2: Fell off the Llama
by ysth (Canon) on Jun 25, 2004 at 05:02 UTC
    The parentheses are just as necessary without the {} construct. If $what is 'fred|barney', you want to match /(fred|barney)(fred|barney)(fred|barney)/, not /fred|barneyfred|barneyfred|barney/.

    I see from fred that fred and barney are fully paid up members of the metasyntactic variable club :)