[26278] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8460 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 26 21:05:18 2005

Date: Mon, 26 Sep 2005 18:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 26 Sep 2005     Volume: 10 Number: 8460

Today's topics:
    Re: Analyzing many $scalars for match - then action <jgibson@mail.arc.nasa.gov>
    Re: regex, number of matches <abigail@abigail.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 26 Sep 2005 16:17:27 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Analyzing many $scalars for match - then action
Message-Id: <260920051617271947%jgibson@mail.arc.nasa.gov>

In article <slrndj5lb4.o1p.nw@granicus.if.org>, Nathan Wagner
<nw@hydaspes.if.org> wrote:

> On 2005-09-22, A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> > "Robert" <rbutcher.nospam@hotmail.com> wrote in
> 
> [snip]
> 
> >> For example (not real code): 
> >> if ($name,$email,$inquiry,$phone,$comments =~ /XXX/) { &terminate; }
> 
> > for( $name, $email, $inquiry, $phone, $comments ) {
> >    terminate if /XXX/;
> > }
> 
> Does grep in a boolean context short circuit?
> 
> terminate() if grep(/XXX/, $name,$email,$inquiry,$phone,$comments);
> 
> or would this be the same as a scalar context and test all the scalars?
> 
> Even if it doesn't short circuit, this may be more programmer efficient.

Judging from the documentation for grep:

   "Evaluates the BLOCK or EXPR for each element of LIST (locally
   setting $_ to each element) and returns the list value consist-
   ing of those elements for which the expression evaluated to
   true.  In scalar context, returns the number of times the
   expression was true."

I would guess that it does not short circuit, else how could it return
the total number of matches?

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: 26 Sep 2005 22:15:50 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regex, number of matches
Message-Id: <slrndjgsom.9lk.abigail@alexandra.abigail.nl>

Dr.Ruud (rvtol+news@isolution.nl) wrote on MMMMCDIX September MCMXCIII in
<URL:news:dh9va1.1f0.1@news.isolution.nl>:
~~  Abigail:
~~ > Dr.Ruud:
~~  
~~ >> The joining "" needs to be a " " for lines that don't have
~~ >> leading or trailing whitespace.
~~ >
~~ > All lines end with a newline, so the space is not needed.
~~  
~~  Maybe you changed the
~~    BEGIN {@data = split /\n/ => <<'--';
~~  to
~~    BEGIN {@data = <<'--';
~~  and I didn't notice.


No, I just went back to the @data = <DATA>. I only used the BEGIN variant
when benchmarking the $&, which required doing stuff before other parts
where seen. And since DATA wasn't seen yet, you couldn't read from DATA.
Hence the @data = split /\n/ => <<'--'; trick for once benchmark only.



Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8460
***************************************


home help back first fref pref prev next nref lref last post