SPUG: /(abc)/g in SCALAR; /g unnecessary

Tim Maher/CONSULTIX tim at consultix-inc.com
Wed Sep 22 13:11:04 CDT 1999


>> Message submitted at: Wed Sep 22 11:11:04 PDT 1999
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 1417      

SPUGers,

Colin said last night that the /g is not needed to get
parenthesized matches returned in the SCALAR context;
unfortunately, at the time, our projectable-laptop wasn't yet
working, so I wasn't able to do a live test to settle the issue.

Having now looked into this, I see that he is correct (as
usual!).  I vaguely remembered a case I had encountered in which
the presence/absence of the /g seemed to make a difference, but
I haven't been able to reproduce it, so until further notice 8-},
I too believe that the /g is not needed to get post-match
variables set!

Thanks for the clarification!
-Tim

P.S.  NOTE: if you want to repeatedly perform matches against
the same string, you'll need /g; that's not what we're talking
about here!

$ cat /tmp/c
#! /usr/bin/perl -w
# Parenthesized matches returned, whether or not /g present

$_='Linux 2.0.36. (POSIX).';
/(\w+)\s+(\w+)/		and  print "Found $1/$2\n";
/(\w+)\s+(\w+)/g	and  print "Found $1/$2\n";

$ /tmp/c
Found Linux/2
Found Linux/2
$ 

*==================================================================*
| Tim Maher, PhD  CEO, Consultix &    (206) 781-UNIX/8649          |
|      Pacific Software Gurus, Inc.   Email: tim at consultix-inc.com |
| "The UNIX/Perl Training Experts"    http://www.consultix-inc.com |
|      FALL SCHEDULE OF PUBLIC UNIX/Perl CLASSES COMING SOON!      |
*==================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list