SPUG: flip-flops

Geoffrey & Kristin Grosenbach glyph at mac.com
Wed Feb 6 12:13:21 CST 2002


Colin--

I'm glad you mentioned the .. operator as a logic operator. I didn't 
know it worked that way in scalar context, but it seems really useful. 
Special operators like that are part of the reason I prefer Perl over 
other languages. (I did read the docs in Perl in a Nutshell and they 
made sense to me.)
I think that a single operator is almost always easier to understand 
than a usually greater number of lines of code. One can lookup an 
operator in a manual, but where do you look for an explanation of a 
tricky loop? So in that sense, the possibly difficult documentation on 
an operator is much more than one would otherwise have.

Geoff


On Wednesday, February 6, 2002, at 12:00  AM, Colin Meyer wrote:

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

http://www.GeoffreyGrosenbach.com


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