At 13:05 2002.01.16, Leon wrote:
>----- Original Message -----
>From: <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Cc: <[EMAIL PROTECTED]>
>>
>> | $key=~/^r(\d+)c(\d+)$/
>> ||\___/|\___/|
>> || | | | `---- end of string
>> || | | `------- one or more digits => $2
>> || | `---------- the letter 'c'
>> || `------------- one or more digits => $1
>> |`---------------- the letter 'r'
>> `----------------- beginning of string
>>
>> Matching $key's would be 'r123c47' or 'r0c99999'.
>
>Fantastic ! Surely the above 'diagram' takes you sometime to type. Its very
>artistic, did you actually type it or use some script.
>Thanks
Less artistic but easier to do would be:
$key=~/^ # beginning of string
r # the letter 'r'
(\d+) # one or more digits => $1
c # the letter 'c'
(\d+) # one or more digits => $2
$ # end of string
/x; # Use extended regular expressions.
and it parse properly in your code (not to mention that the comments are in order).
Here's a quote from Programing Perl:
"The /x modifier itself needs a little more explanation. It tells the regular
expression parser to ignore whitespace that is not backslashed or within a character
class. You can use this modifier to break up your regular expression into (slightly)
more readable parts. The # character is also treated as a metacharacter introducing a
comment, just as in ordinary Perl code. Taken together, these features go a long way
toward making Perl a readable language."
We might as well get use to it. I think I read somewhere that it is going to be the
default behavior of the m// and s/// operators in Perl 6.
Best
-----------------------------------------------------------
�ric Beaudoin <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]