[Chicago-talk] string operator question.

Kent Cowgill kent at c2group.net
Sat Sep 12 08:15:35 PDT 2009

On Sep 12, 2009, at 9:42 AM, Richard Reina <richard at rushlogistics.com>  

> I think I've got it now. I found this:
> $mystring = "[2004/04/13] The date of this article.";
> 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/5fa03d87/attachment.html>

More information about the Chicago-talk mailing list