[Brisbane-pm] To Chomp or not to Chomp

Robert Loomans robertl at apnic.net
Tue Feb 27 04:02:31 PST 2007


> When you assign to the *result of a bind* in *list context* you get back a 
> list of all the match capture values:

Minor nit: m// and s/// differ in this respect.

m// works as you describe (from the perlop man page):

>        m/PATTERN/cgimosx
>        /PATTERN/cgimosx
>                Searches a string for a pattern match, and in scalar context
>                returns true if it succeeds, false if it fails.
> ...
>                If the "/g" option is not used, "m//" in list context returns a
>                list consisting of the subexpressions matched by the parenthe-
>                ses in the pattern, i.e., ($1, $2, $3...).  (Note that here $1
>                etc. are also set, and that this differs from Perl 4's behav-
>                ior.)  When there are no parentheses in the pattern, the return
>                value is the list "(1)" for success.  With or without parenthe-
>                ses, an empty list is returned upon failure.

s/// *always* returns the number of matches (from the perlop man page):

>  s/PATTERN/REPLACEMENT/egimosx
>                Searches a string for a pattern, and if found, replaces that
>                pattern with the replacement text and returns the number of
>                substitutions made.  Otherwise it returns false (specifically,
>                the empty string).

Rob

-- 
Robert Loomans                                 Email:  robertl at apnic.net
Programmer/Analyst, APNIC                      Phone:    +61 7 3858 3100
http://www.apnic.net                             Fax:    +61 7 3858 3199
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3818 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070227/5b28b726/attachment-0001.bin 


More information about the Brisbane-pm mailing list