SPUG: flip-flops

Colin Meyer cmeyer at helvella.org
Wed Feb 6 02:00:38 CST 2002


Hi Jason,

On Tue, Feb 05, 2002 at 08:24:30PM -0800, dancerboy wrote:
> At 4:15 pm -0800 2/5/02, Colin Meyer wrote:
> >
> >I really like the flip-flop operator.  It reminds me of learning boolean
> >logic by wiring together nand gates.  It's also incredibly useful in
> >one liners:
> >   # print out the contents of <foo> </foo> tags:
> >   pyx file.xml |perl -ne'print if /^\(foo/../^\)foo/' |pyxw
> >
> >Have fun,
> >-C.
> >
> 
> Ugh.  Reading that section of the docs made my brain hurt.  For code 
> that anyone else is going to have to read, please consider 
> implementing .. with "normal" boolean operators (and, or, not) 
> instead.  Some language features are best left unused, IMO. 
> (Remember, TMTOWTDI...)
> 
> -jason

How about suggesting an easy-to-read substitute for scalar .. using
"normal" boolean operators?

Here's the above perl one liner so rendered:

  #!perl -n
  if (not $in_foo and /^\(foo/) { $in_foo=1 }
  print if $in_foo;
  if ($in_foo and /^\(foo/) { $in_foo=0 }

I find the scalar .. to be far more readable. Having once gone through
the learning process (reading the painful docs), it is easier to use
than the wordier alternative.

I found the learning process for regular expressions to be far more
difficult than that for understanding scalar .. . I think that
anyone would agree. To avoid that painful learning process, one
could loop across a string character by character and use "normal"
conditional constructs to test for or extract certain data. Who
would recommend that? ;-)

Have fun,
-C.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list