[28388] in Perl-Users-Digest
Perl-Users Digest, Issue: 9752 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 21 18:15:26 2006
Date: Thu, 21 Sep 2006 15:15:11 -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 Thu, 21 Sep 2006 Volume: 10 Number: 9752
Today's topics:
Repeated captures from the same pattern and string <brandon.n.atkinson@gmail.com>
Re: Repeated captures from the same pattern and string <David.Squire@no.spam.from.here.au>
Re: Repeated captures from the same pattern and string <wahab@chemie.uni-halle.de>
Re: Russel Quong's "Perl in 20 pages" <uri@stemsystems.com>
Re: Russel Quong's "Perl in 20 pages" <wahab@chemie.uni-halle.de>
Re: Russel Quong's "Perl in 20 pages" <David.Squire@no.spam.from.here.au>
Re: Russel Quong's "Perl in 20 pages" <wahab@chemie.uni-halle.de>
Re: Russel Quong's "Perl in 20 pages" <mritty@gmail.com>
Re: Russel Quong's "Perl in 20 pages" <eflorac@imaginet.fr>
Re: Russel Quong's "Perl in 20 pages" <wahab@chemie.uni-halle.de>
Re: Russel Quong's "Perl in 20 pages" <kkeller-usenet@wombat.san-francisco.ca.us>
Re: sort with Perl .. <xicheng@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Sep 2006 13:26:14 -0700
From: "gorjusborg" <brandon.n.atkinson@gmail.com>
Subject: Repeated captures from the same pattern and string
Message-Id: <1158870374.657595.294650@e3g2000cwe.googlegroups.com>
I'm trying to match a string (which happens to be an entire file) as
many times as it can, and capture a portion to a variable.
The results I'm getting with the method I'm trying to use are..
unexpected.
Here is the code:
while ($text =~ m{$pattern1($pattern2)$pattern3\(}msg) {
push @instance, "$1";
}
I've shortened the patterns I'm using to place holders because they are
pretty complex, and I'm pretty sure they're working as I expect.
The problem is, though I'm getting the _number_ of matches I'd expect
(verified visually), I'm only getting the captured text from the first
match in $1, but repeated the number of times the pattern matches in
the text... What gives??
=Brandon=
------------------------------
Date: Thu, 21 Sep 2006 21:45:34 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Repeated captures from the same pattern and string
Message-Id: <eeutke$stb$1@gemini.csx.cam.ac.uk>
gorjusborg wrote:
> I'm trying to match a string (which happens to be an entire file) as
> many times as it can, and capture a portion to a variable.
> The results I'm getting with the method I'm trying to use are..
> unexpected.
>
> Here is the code:
>
> while ($text =~ m{$pattern1($pattern2)$pattern3\(}msg) {
> push @instance, "$1";
> }
>
> I've shortened the patterns I'm using to place holders because they are
> pretty complex, and I'm pretty sure they're working as I expect.
>
> The problem is, though I'm getting the _number_ of matches I'd expect
> (verified visually), I'm only getting the captured text from the first
> match in $1, but repeated the number of times the pattern matches in
> the text... What gives??
Could you please show us an example consisting of a small but *complete*
script including data and results, so we can see exactly how things are
"unexpected" and try it out for ourselves?
See the posting guidelines for this group, which are posted here twice
weekly. Following them will help you to help the group to help you.
DS
------------------------------
Date: Thu, 21 Sep 2006 22:59:02 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Repeated captures from the same pattern and string
Message-Id: <eeuune$d7v$1@mlucom4.urz.uni-halle.de>
Thus spoke gorjusborg (on 2006-09-21 22:26):
> while ($text =~ m{$pattern1($pattern2)$pattern3\(}msg) {
> push @instance, "$1";
> }
> ...
> The problem is, though I'm getting the _number_ of matches I'd expect
> (verified visually), I'm only getting the captured text from the first
> match in $1, but repeated the number of times the pattern matches in
> the text... What gives??
The code posted seems so far ok, which means your
error is somewhere else. As David pointed out,
please post some code that allows us to
replicate your problem.
I did run your (slightly modified, see "$1")
code against some random Nietzsche paragraph
in order to find out all non capitalized
words between two capitalized ones - and
your code indeed did work:
...
$text = do { local $/; <DATA> }; # pull some Nietzsche stuff ;-)
$pattern1 = '\b[A-Z][a-z]+\s+';
$pattern2 = '[a-z]+';
$pattern3 = '\s+[A-Z][a-z]+';
while( $text =~ m{$pattern1($pattern2)$pattern3}gms ) {
push @instance, $1;
}
print join "\n", @instance;
...
__DATA__
(put your favorite quote here)
Regards
Mirco
------------------------------
Date: Thu, 21 Sep 2006 14:20:34 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <x7d59pf5e5.fsf@mail.sysarch.com>
>>>>> "MFM" == Mister Fred Ma <Mister.Fred.Ma@gmail.com> writes:
MFM> Does anyone know where the latest version can be found? A cached
MFM> version of Document version 2001a is available at
MFM> http://tinyurl.com/h6c7d
MFM> (http://72.14.207.104/search?q=cache:vEXjoSaJs20J:quong.best.vwh.net/perlin20/+http://quong.best.vwh.net/perlin20/&hl=en&gl=ca&ct=clnk&cd=1).
MFM> It's the latest I can find, but the server hosting the original is not
MFM> available. I haven't seen recent references to the document on Google
MFM> or Groups. Thanks.
i love reading bad perl web tutes. this is as bad as they get. this
paragraph alone highlights the total confusion of the author. could he
have used any more hash synonyms?
A hash variable stores a array of (key, value) pairs,
collectively known as a map. Typically, the key and value are
different but related values, such as a person's name and phone
number. A hash is implemented in Perl so that you can quickly
look up the value given the key, when there are many (key,
value) pairs. From a algorithms/data structures standpoint, a
Perl hash implements a dictionary, mostly likely using a hash
table.
wow.
we do need to make a bad perl web tute site with links and reviews. in
my copious free time i will do this. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 21 Sep 2006 20:50:07 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <eeun5n$a4q$1@mlucom4.urz.uni-halle.de>
Thus spoke Mister.Fred.Ma@gmail.com (on 2006-09-21 13:06):
> Does anyone know where the latest version can be found? A cached
> version of Document version 2001a is available at
> http://tinyurl.com/h6c7d
> (http://72.14.207.104/search?q=cache:vEXjoSaJs20J:quong.best.vwh.net/perlin20/+http://quong.best.vwh.net/perlin20/&hl=en&gl=ca&ct=clnk&cd=1).
> It's the latest I can find, but the server hosting the original is not
> available.
Ths has been updated lately and is now available
in a *much* *much* better Version, *2.0* I'd guess.
It now includes a comparison w/Python too - as a bonus ...
http://www.adequacy.org/stories/2001.12.20.165434.32.html
Regards & scnr
Mirco
(LOL)
------------------------------
Date: Thu, 21 Sep 2006 20:03:19 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <eeunko$huf$2@gemini.csx.cam.ac.uk>
Mirco Wahab wrote:
> It now includes a comparison w/Python too - as a bonus ...
> http://www.adequacy.org/stories/2001.12.20.165434.32.html
Hey! That's off-topic here. It's about some language called 'Pearl' :)
DS
------------------------------
Date: Thu, 21 Sep 2006 21:16:14 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <eeuoml$afm$1@mlucom4.urz.uni-halle.de>
Thus spoke David Squire (on 2006-09-21 21:03):
> Mirco Wahab wrote:
>
>> It now includes a comparison w/Python too - as a bonus ...
>> http://www.adequacy.org/stories/2001.12.20.165434.32.html
>
> Hey! That's off-topic here. It's about some language called 'Pearl' :)
Uhmmm, right - this should have been about 'Gloria' then ...
BTW. ( from http://www.linuxjournal.com/article/3394 ):
<blockquote>
....
Marjorie: Okay, is Perl perfect now or
do you continue to do further development?
Larry: Hmm, the two are not mutually exclusive.
Look at Linux. :-)
...
</blockquote>
I like these guys ...
Regards
Mirco
------------------------------
Date: 21 Sep 2006 12:23:53 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <1158866633.222146.227770@i3g2000cwc.googlegroups.com>
Mirco Wahab wrote:
> Thus spoke Mister.Fred.Ma@gmail.com (on 2006-09-21 13:06):
>
> > Does anyone know where the latest version can be found? A cached
> > version of Document version 2001a is available at
> > http://tinyurl.com/h6c7d
> > (http://72.14.207.104/search?q=cache:vEXjoSaJs20J:quong.best.vwh.net/perlin20/+http://quong.best.vwh.net/perlin20/&hl=en&gl=ca&ct=clnk&cd=1).
> > It's the latest I can find, but the server hosting the original is not
> > available.
>
> Ths has been updated lately and is now available
> in a *much* *much* better Version, *2.0* I'd guess.
>
> It now includes a comparison w/Python too - as a bonus ...
> http://www.adequacy.org/stories/2001.12.20.165434.32.html
That's *better*? Well, it's updated certainly, but it's still rife
with errors, misleading statements, and bias. I sincerely hope no
one's trying to learn either Perl or Python from drivel like this...
Paul Lalli
------------------------------
Date: Thu, 21 Sep 2006 21:24:13 +0200
From: Emmanuel Florac <eflorac@imaginet.fr>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <pan.2006.09.21.19.24.13.266461@imaginet.fr>
Le Thu, 21 Sep 2006 20:50:07 +0200, Mirco Wahab a écrit :
>
> Ths has been updated lately and is now available in a *much* *much* better
> Version, *2.0* I'd guess.
Actually, I'm afraid this article in some way tries tries (and
fails) to be funny. Too bad.
--
Pluralitas non est ponenda sine necessitate.
Guillaume d'Ockham.
------------------------------
Date: Thu, 21 Sep 2006 21:36:50 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <eeupt9$aqg$1@mlucom4.urz.uni-halle.de>
Thus spoke Emmanuel Florac (on 2006-09-21 21:24):
> Le Thu, 21 Sep 2006 20:50:07 +0200, Mirco Wahab a écrit :
>
> Actually, I'm afraid this article in some way tries tries (and
> fails) to be funny. Too bad.
Maybe you're right, *but* - (imho) this is by far the
best /tries_tries_(and_fails)_to_be_funny/ article
in this special kind of "anti-humor" I know of ;-)
(I think even Larry could have had laughed at it ...)
Regards
Mirco
------------------------------
Date: Thu, 21 Sep 2006 13:35:34 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <ml9bu3xvue.ln2@goaway.wombat.san-francisco.ca.us>
On 2006-09-21, Uri Guttman <uri@stemsystems.com> wrote:
>
> i love reading bad perl web tutes. this is as bad as they get. this
> paragraph alone highlights the total confusion of the author. could he
> have used any more hash synonyms?
>
> A hash variable stores a array of (key, value) pairs,
> collectively known as a map. Typically, the key and value are
> different but related values, such as a person's name and phone
> number. A hash is implemented in Perl so that you can quickly
> look up the value given the key, when there are many (key,
> value) pairs. From a algorithms/data structures standpoint, a
> Perl hash implements a dictionary, mostly likely using a hash
> table.
He forgot ''associative array''. ;-)
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
Date: 21 Sep 2006 14:34:47 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: sort with Perl ..
Message-Id: <1158874487.402825.154970@m7g2000cwm.googlegroups.com>
Mirco Wahab wrote:
> Thus spoke Xicheng Jia (on 2006-09-21 16:44):
>
> > on the command line:
> >
> > echo 'xxxxx bbb jjjj
> > bbbbb cccc yyyyy
> > cccccc ppppp kkkk
> > ddddddd llllll ssssss
> > ' | perl -alne '
> > $hash{ $F[2] } = $_
> > }{
> > print $hash{$_} for sort keys %hash
> > '
>
> This would require to have unique column #N
> elements, otherwise they'd get dropped, afaik ...
I guess you meant getting unique and thus dropping some records by
using the values of col#3 as hash keys, and then you are right.
When I saw "column #N elements", I thought it was the number of
columns/fields in a record(like NF in awk). :-)
Regards,
Xicheng
------------------------------
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 9752
***************************************