R. Joseph Newton wrote:
> Rob Dixon wrote:
>
> >
> > The /net|gaat/ construct is the most usual one, but this may
> > be of some use to you:
> >
> >     for ( $node ) {
> >         if ( /net/ || /gaat/ ) {
> >             :
> >         }
> >     }
> >
> > which makes use of the 'foreach' loop aliasing each list element
> > with $_ within the loop. The loop will only execute once and
> > within it you can make use of built-in operators that use $_ as a
> > default parameter.
> >
> > HTH,
> >
> > Rob
>
> Which is actually logically equivalent to what he had, but typographically neater, 
> since the
> '$_ =~ ' is implicitly tacked on to each operand of the '||'.  ;:-o)

Yes, but there's a lot to be said for typographical neatness. Without
it you often can't see the bugs for code. It's also a Good Idea if the
implementation of a solution expresses the way that solution works
rather than just being a way of getting a computer to execute it.
Anyway there's no getting around the fact that there have to be
two comparisons, so any alternative coding will be aesthetic.

In English you would say "if the node contains 'net' or 'gaat'" which takes
advantage of 'node' being checked both times. With Larry's linguistic
background I'm sure he'd agree with me that $_ is very like a pronoun.
I think of it as something like 'it' or 'this'. My code above would be
like saying, "Examine the node. If it contains 'net' or 'gaat'...". Likewise
in the following:

    foreach (@array) {
        s/^\s//;
        s/\s+$//;
    }

we have, "For each array element, remove whitespace from the beginning
(of it) and remove whitespace from the end (of it)." The optional 'of it'
parallels the optional '$_ =~ ' in the statement.

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to