develooper Front page | perl.beginners | Postings from April 2003

Re: question about || operator

Thread Previous | Thread Next
From:
R. Joseph Newton
Date:
April 1, 2003 11:33
Subject:
Re: question about || operator
Message ID:
3E89EA43.4AA1445C@efn.org
Rob Dixon wrote:

> Ravi Malghan wrote:
> > Hello: I seem to have forgotten
> >
> > Can this statement be shortened
> > if(($node =~ /net/) || ($node =~ /gaat/))
> >
> > The following does not give me the expected results
> > if($node =~ (/net/ || /gaat/) )
>
> 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)

Joseph


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About