[Chicago-talk] string operator question.
Richard Reina
richard at rushlogistics.com
Sat Sep 12 08:42:16 PDT 2009
Thank you Kent. Obviously I missed that.
>
> Chicago.pm chatter <chicago-talk at pm.org> wrote: > On Sep 12, 2009, at 9:42 AM, Richard Reina <richard at rushlogistics.com> wrote:
> > I think I've got it now. I found this:
>
>
> if($mystring =~ m/(\d+)/) {
> print "The first number is $1.";
> }
>
> in a tutorial at http://www.somacon.com/p127.php
>
> and hacked it up so that my number gets the value
> of
>
> $number = $1
>
> and it works.
>
> However, I am confused by the representation of the
> scalar $1 I have never seen that before. Can someone
> explain $1. Or is it something that should not be
> explained but instead accepted at face value?
It says on that page, right above your example:
>
> Prints "The first digit is 2." In order to designate
> a pattern for extraction, one places parenthesis around
> the pattern. If the pattern is matched, it is returned
> in the Perl special variable called $1. If there are
> multiple parenthesized expressions, then they will
> be in variables $1, $2, $3, etc.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20090912/466163e3/attachment-0001.html>
More information about the Chicago-talk
mailing list