[Brisbane-pm] Regex Syntax - Context is everything
Damian James
djames at thehub.com.au
Mon Apr 16 23:29:07 PDT 2007
On 17/04/2007, at 2:08 PM, Martin Jacobs wrote:
>
> ($rain) = ($rain =~ m|(\d+(:?\.\d+)?)|x);
>
> I had read about list and scalar context, but I must admit that it
> I could not make any sense of it at the time.
Can also do:
$rain = ($rain =~ m|(\d+(:?\.\d+)?)|x)[0];
Which is a list slice with one element. You could make the index -1
to always pick the last match, if there are multiple, and that would
be the same as the behaviour above. The version I gave picks the
first match
Cheers
Damian
More information about the Brisbane-pm
mailing list