SPUG: Range Operator is COOL!

Tim Maher/CONSULTIX tim at consultix-inc.com
Mon Nov 29 12:22:42 CST 1999


SPUGers,
 
Perl is so cool! 8-}

In reading the Pattern Matching chapter of the Cookbook, in preparation
for the 12/21 meeting, I was reminded of the existence of the
(scalar) Range Operator, "..", which I hadn't used much before. (I've
used it frequently in AWK, but something about the mindset of Perl
programming had steered me away from it.)

I've found it useful for doing some pretty cool stuff, including
matching text between lines that are identified by a final match that
is dependent on the initial match (using $1):


$ cat test.html
<H1>
Heading Level 1
</H1>
STUFf
<h2>
Heading Level 2
</h2>
MORE STUFf
<H1> Heading Level 1
</H1>

$ perl -ne '/<H(\d)>/ .. m|</H$1>| and  print;'  test.html
<H1>
Heading Level 1
</H1>
<H1> Heading Level 1
</H1>
$

*============================================================*
| Tim Maher, PhD  Consultix &   (206) 781-UNIX/8649          |
|  Pacific Software Gurus, Inc  Email: tim at consultix-inc.com |
|  UNIX/Linux & Perl Training   http://www.consultix-inc.com |
|Classes: 12/7 UNIX Fund; 12/13 Perl+Modules; 1/18 Int. Perl |
*============================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    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