[26277] in Perl-Users-Digest
Perl-Users Digest, Issue: 8459 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 26 18:05:33 2005
Date: Mon, 26 Sep 2005 15:05:09 -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: 8459
Today's topics:
Re: Analyzing many $scalars for match - then action <nw@hydaspes.if.org>
Matching Multiple Patters In A Regex In Any Order <hal@thresholddigital.com>
Re: print @{1} versus print @{11} <tadmc@augustmail.com>
Re: regex, number of matches <rvtol+news@isolution.nl>
Re: regex, number of matches <rvtol+news@isolution.nl>
Re: regex, number of matches <abigail@abigail.nl>
Re: regex, number of matches <rvtol+news@isolution.nl>
start firefox or mozilla with username and password <ngoc@yahoo.com>
Re: start firefox or mozilla with username and password <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 Sep 2005 16:01:40 +0000 (UTC)
From: Nathan Wagner <nw@hydaspes.if.org>
Subject: Re: Analyzing many $scalars for match - then action
Message-Id: <slrndj5lb4.o1p.nw@granicus.if.org>
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.
--
Nathan Wagner
------------------------------
Date: Mon, 26 Sep 2005 16:35:19 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Matching Multiple Patters In A Regex In Any Order
Message-Id: <hYWdncBlYtYbxqXeRVn-jQ@comcast.com>
I've been reading the FAQ on Regexes and I see I can map to create an array
of patterns to be found in a Regex, like this:
@patterns = map { qr/\b$_\b/i } qw( foo bar baz );
LINE: while( <> ) {
foreach $pattern ( @patterns ) {
print if /\b$pattern\b/i;
next LINE;
}
}
And the next example talks about backtracking, as well.
I think I remember, at some point, reading how it was possible to specify an
array or hash in a regex to see if one or more of multiple matches were
found, someting like:
@pattern = qw(foo bar baz);
if ($line =~ /@pattern/) {print "Found a match!\n";}
I KNOW that does not work, as is, but I've been trying to find out if there
was something similar using an array or hash to check multiple values. I
thought I remembered also being able to do something like:
@pattern = qw(fooba? f.*?bar);
(@found) = $line =~ /@pattern/);
Which would find all the matches for both regexes specified in @pattern and
put them all in @found.
Is this possible? Is there some way, other than interating through a loop,
to match multiple patterns?
Thanks!
Hal
------------------------------
Date: Mon, 26 Sep 2005 13:06:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: print @{1} versus print @{11}
Message-Id: <slrndjge5m.epm.tadmc@magna.augustmail.com>
xhoster@gmail.com <xhoster@gmail.com> wrote:
> fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
>> * In perldoc perlop, if you search for '@{' you find this gem:
>>
>> "Punctuation" arrays such as @+ are only interpolated if the name is
>> enclosed in braces @{+}.
>>
>> Now, what on earth is a "punctuation" array and why is "punctuation" in
>> quotes?
>
> A punctuation array is an array whose name is composed of punctuation. It
> is in quotes because the other of perlop is notifying you that he is either
> coining the term, or is using the term advisedly.
Perhaps the author quoted it because he had $^I in mind, which
not strictly all punctuation characters.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 26 Sep 2005 21:01:09 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh9o1h.138.2@news.isolution.nl>
John Bokma schreef:
> And what is \&?
A message for the regex engine.
> And where is the info it contains stored?
Not in something accessible on the 'Perl-level'.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 26 Sep 2005 20:59:26 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh9o1h.138.1@news.isolution.nl>
Abigail schreef:
> Dr.Ruud:
>> sub3 => '$sub3 = 0; $sub3 += s/\S+/./g for @data;',
>> while => '$while = 0; do {$while++ while /\S+/g} for @data;',
>>
>> while 11120/s 109% 105% 59% -- -34%
>> sub3 16809/s 216% 210% 140% 51% --
>
> That's not a fair benchmark. After the first iteration, all the
> sequences of non-space characters have been collapsed to single
> characters -
> reducing the sizes of the strings to match against. And that's of
> course faster. It will also influence all tests run after the 'sub3'
> test.
Aaargh. The destructive sub was run on a copy @data, to prevent any
influence on following runs, sorry for not making that clear.
But I hadn't thought of the side effects with the iterations.
> a way to speed up the counting of words,
> and that involves entering the regexp engine once,
> instead of once for each line: [...]
>
> while => '$while = 0; do {$while ++ while /\S+/g} for
@data;',
> join => '$join = 0; my $c = join "" => @data;
> $join ++ while $c =~ /\S+/g', [...]
>
> while 5019/s 142% 74% 71% -- -16%
> join 5973/s 188% 107% 103% 19% --
The joining "" needs to be a " " for lines that don't have leading or
trailing whitespace.
Since we seem to be getting in a word counting contest ;)
consider this:
split => '$split = 0; $split += split for @data'
(but I didn't check the benchmarking side effects, again)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 26 Sep 2005 20:31:20 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regex, number of matches
Message-Id: <slrndjgmko.9lk.abigail@alexandra.abigail.nl>
Dr.Ruud (rvtol+news@isolution.nl) wrote on MMMMCDIX September MCMXCIII in
<URL:news:dh9o1h.138.1@news.isolution.nl>:
:) Abigail schreef:
:)
:) > a way to speed up the counting of words,
:) > and that involves entering the regexp engine once,
:) > instead of once for each line: [...]
:) >
:) > while => '$while = 0; do {$while ++ while /\S+/g} for
:) @data;',
:) > join => '$join = 0; my $c = join "" => @data;
:) > $join ++ while $c =~ /\S+/g', [...]
:) >
:) > while 5019/s 142% 74% 71% -- -16%
:) > join 5973/s 188% 107% 103% 19% --
:)
:) 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.
:) Since we seem to be getting in a word counting contest ;)
:) consider this:
:)
:) split => '$split = 0; $split += split for @data'
:)
:) (but I didn't check the benchmarking side effects, again)
That doesn't modify the data, so that fine. It's even faster.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Mon, 26 Sep 2005 23:12:12 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <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.
> That doesn't modify the data, so that fine.
OK. It think it changes somebody else's @_, but inside an eval that
should not be a problem.
> It's even faster.
Yep.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 26 Sep 2005 21:26:16 +0200
From: ngoc <ngoc@yahoo.com>
Subject: start firefox or mozilla with username and password
Message-Id: <4338582a$1@news.broadpark.no>
Hi
I use 'exec mozilla http://username:password@www.mysite.com'. But I
still have to type in username and password each time (tiredly). Is
there any other way than this?
------------------------------
Date: Mon, 26 Sep 2005 21:07:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: start firefox or mozilla with username and password
Message-Id: <Xns96DDAE36DB5C4asu1cornelledu@127.0.0.1>
ngoc <ngoc@yahoo.com> wrote in news:4338582a$1@news.broadpark.no:
> I use 'exec mozilla http://username:password@www.mysite.com'. But I
> still have to type in username and password each time (tiredly). Is
> there any other way than this?
What is your Perl question?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
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 8459
***************************************