[31933] in Perl-Users-Digest
Perl-Users Digest, Issue: 3196 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 3 09:09:26 2010
Date: Wed, 3 Nov 2010 06:09:10 -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 Wed, 3 Nov 2010 Volume: 11 Number: 3196
Today's topics:
Could you give me some explanation on this Perl line <rxjwg98@gmail.com>
Re: Could you give me some explanation on this Perl lin <rxjwg98@gmail.com>
Re: Could you give me some explanation on this Perl lin <rxjwg98@gmail.com>
Re: Could you give me some explanation on this Perl lin <rxjwg98@gmail.com>
Re: Could you give me some explanation on this Perl lin <NoSpamPleaseButThisIsValid3@gmx.net>
Re: Counting blocks of text sln@netherlands.com
Re: Foreach <xhoster@gmail.com>
Re: Foreach sln@netherlands.com
Re: Foreach <hhr-m@web.de>
Re: Foreach <NoSpamPleaseButThisIsValid3@gmx.net>
How to download the complete Perl pdf doc <rxjwg98@gmail.com>
Re: How to download the complete Perl pdf doc <tadmc@seesig.invalid>
Re: use of "delete" for hash keys <ela@yantai.org>
Re: use of "delete" for hash keys <jimsgibson@gmail.com>
Re: use of "delete" for hash keys <tadmc@seesig.invalid>
Wildcard matching <jwcarlton@gmail.com>
Re: Wildcard matching <dsfqsdf@poupidoup.com>
Re: Wildcard matching <willem@snail.stack.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 3 Nov 2010 04:37:44 -0700 (PDT)
From: fl <rxjwg98@gmail.com>
Subject: Could you give me some explanation on this Perl line
Message-Id: <d5eb7d81-151c-458b-bfcb-103de3d1a0fe@j18g2000yqd.googlegroups.com>
Hi,
I just begin Perl learning. A sample Perl program is relevant to my
project. After reading some on Perl, I still do not understand the
first line of this sample, see below. Could you help me on its
meaning? Thanks in advance.
eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
------------------------------
Date: Wed, 3 Nov 2010 04:41:47 -0700 (PDT)
From: fl <rxjwg98@gmail.com>
Subject: Re: Could you give me some explanation on this Perl line
Message-Id: <975c5256-dbb7-4747-94de-5195ac8aef99@30g2000yql.googlegroups.com>
On 3 nov, 07:37, fl <rxjw...@gmail.com> wrote:
> Hi,
> I just begin Perl learning. A sample Perl program is relevant to my
> project. After reading some on Perl, I still do not understand the
> first line of this sample, see below. Could you help me on its
> meaning? Thanks in advance.
>
> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
More specific here. Why there is one more $ in the first argument? \$
$1 means '$1'? I still do not understand the reason for this. Second,
There is no definition on w, what is the \w+ for? Thanks
------------------------------
Date: Wed, 3 Nov 2010 04:52:32 -0700 (PDT)
From: fl <rxjwg98@gmail.com>
Subject: Re: Could you give me some explanation on this Perl line
Message-Id: <30b93044-7f22-4844-ad02-fd29b387b5ef@l8g2000yql.googlegroups.com>
On 3 nov, 07:37, fl <rxjw...@gmail.com> wrote:
> Hi,
> I just begin Perl learning. A sample Perl program is relevant to my
> project. After reading some on Perl, I still do not understand the
> first line of this sample, see below. Could you help me on its
> meaning? Thanks in advance.
>
> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
More specific here. Why there is one more $ in the first argument? \$
$1 means '$1'? I still do not understand the reason for this. Thanks
------------------------------
Date: Wed, 3 Nov 2010 04:56:02 -0700 (PDT)
From: fl <rxjwg98@gmail.com>
Subject: Re: Could you give me some explanation on this Perl line
Message-Id: <6c722ce4-dc30-4270-83ea-580052ce50bd@v16g2000yqn.googlegroups.com>
On 3 nov, 07:37, fl <rxjw...@gmail.com> wrote:
> Hi,
> I just begin Perl learning. A sample Perl program is relevant to my
> project. After reading some on Perl, I still do not understand the
> first line of this sample, see below. Could you help me on its
> meaning? Thanks in advance.
>
> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
More specific here. Why there is one more $ in the first argument? \$
$1 means '$1'? I still do not understand the reason for this.
In order to understand it clearly, could you write the above line in
several small lines?
Thanks
------------------------------
Date: Wed, 03 Nov 2010 13:22:24 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Could you give me some explanation on this Perl line
Message-Id: <4cd15401$0$6978$9b4e6d93@newsspool4.arcor-online.net>
On 03.11.2010 12:37, fl wrote:
> Hi,
> I just begin Perl learning. A sample Perl program is relevant to my
> project. After reading some on Perl, I still do not understand the
> first line of this sample, see below. Could you help me on its
> meaning? Thanks in advance.
>
>
> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
This piece of code should NOT be relevant to your project as it is very
bad code.
eval
"\$$1=\$2" <--- It creates a variable called $1 and assign the value
$2 to it. You should NOT do this, use a hash instead. Read
perldoc -q "variable name" for an explanation.
while
@ARGV Do this for all command line arguments
&& $ARGV[0]=~ /^(\w+)=(.*)/ as long as it looks like var=value
&& shift; and remove this command line arg
Better use Getopt! See
perldoc Getopt::Std
perldoc Getopt::Long
Also always "use strict; use warnings;" in all your programs. The above
example will not even compile with "use strict". That is a clear sign
that something should be changed in the code.
Wolf
------------------------------
Date: Tue, 02 Nov 2010 20:52:03 -0700
From: sln@netherlands.com
Subject: Re: Counting blocks of text
Message-Id: <tpl1d654or4eij2hk7j8msu3nrt1f1qh4h@4ax.com>
On Tue, 02 Nov 2010 10:32:40 -0500, "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:
>laredotornado wrote:
>> Hi,
>>
>> I'm using Perl 5.8.9 for Mac 10.6.3. I am trying to parse log files
>> (log4j v1.2.4) and count identical blocks of text in my file. So
>> below is an example of the kinds of things I see in my log file
>> (notice that some blocks of text span several lines). I would like to
>> get identify the similar blocks of text and get a count of how many
>> times each occurs in the file. Any ideas how I can do this?
>
>>
>> =====================example contents of a file =====================
>> ERROR com.myco.servlet.summer.SummerServlet - db gave null for
>> galleryId: 4
>> ERROR com.myco.servlet.common.SimpleLeadTrackerServlet - LEAD
>> INSERTION FAILED: Laughlin null null
>> com.ibatis.common.jdbc.exception.NestedSQLException:
>[... removed hundreds of useless errors... ]
>
>> at
>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:
>> 167)
>> ... 33 more
>You post hundreds of lines of errors, and don't include the last 33..
>Very thoughtful. Next time, there's no need to post that many lines,
>just post a few, showing different errors.
>
>You don't say what you have already tried, but before you start
>to write the code, first you need to define what you want to look
>for in the file, that would constitute an error. e.g. does every
>error start with 'ERROR '??, Does it start with a capital
>letter?, etc.
>
>Then you have to open the file and look for when that happens,
>and keep track of the error and how many times it happened.
>
>There are different ways to do it, but in general you'd:
>
>open the file.
>while you read the file, possibly line by line....
> if the line contains the indicator of a new error.
> if there was already a previous error that was found, then
> store that previous, error.. maybe in a hash, and
> increment the count.. e.g. $hash{ $error }++;
> store the line as an error. $error = $_
> else append the line to the previous error e.g. $error .= $_
>close the file.
>Be sure to capture the last error.. $hash{ $error }++;
>
>Iterate through the keys in %hash, which are really the text of the
>error, to find the error and how many times it occurred.
>
>perldoc perlopentut
>perldoc perlretut
>perldoc -q 'How do I process an entire hash'
>
You may want to add some bigger indenting to separate
the apparent inner if/else from the apparent outer
if/else. There is only one else.
> if the line contains the indicator of a new error.
>
> if there was already a previous error that was found, then
> store that previous, error.. maybe in a hash, and
> increment the count.. e.g. $hash{ $error }++;
> store the line as an error. $error = $_
>
> else
> append the line to the previous error e.g. $error .= $_
Still, ERROR
...
...
to ERROR
will consume the entire log file as chopped up hash keys.
-sln
------------------------------
Date: Tue, 02 Nov 2010 17:38:10 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Foreach
Message-Id: <4cd0adcc$0$7308$ed362ca5@nr5-q3a.newsreader.com>
Helmut Richter wrote:
> On Tue, 2 Nov 2010, Sherm Pendley wrote:
>
>> It's more accurate to say that 'iteration over a list' executes more
>> rapidly than a C-style loop, regardless of which keyword one happens
>> to use for either one.
>
> That is, if I write "for my $i (1..1000000000)" I can be sure that perl
> will not start by building a list of a billion entries?
Only if you are sure you perl is not ancient.
But even small variations will cause problems.
for ("a", 1..100000000) will build the entire list. So will
for (reverse 1..100000000).
At least in 5.8.8
Xho
------------------------------
Date: Tue, 02 Nov 2010 21:16:06 -0700
From: sln@netherlands.com
Subject: Re: Foreach
Message-Id: <qqn1d61975esqdnbb2h2oumrkidss18q8m@4ax.com>
On Tue, 2 Nov 2010 07:13:56 -0700 (PDT), perler wannabe <bandar.coal@gmail.com> wrote:
>Hi,
>
>I read from a book that "for" is actually "foreach".
The foreach keyword is actually a synonym for the 'for' keyword,
>And foreach is >preferable in Perl.
so you can use foreach for readability or 'for' for brevity.
-sln
------------------------------
Date: Wed, 3 Nov 2010 10:42:07 +0100
From: Helmut Richter <hhr-m@web.de>
Subject: Re: Foreach
Message-Id: <Pine.LNX.4.64.1011031041000.4537@lxhri01.ws.lrz.de>
On Tue, 2 Nov 2010, sln@netherlands.com wrote:
> so you can use foreach for readability or 'for' for brevity.
Or "foreach" for lists and "for" for C-style loops. So you see already at
the keywords what to look for.
--
Helmut Richter
------------------------------
Date: Wed, 03 Nov 2010 13:41:30 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Foreach
Message-Id: <4cd1587b$0$6988$9b4e6d93@newsspool4.arcor-online.net>
On 03.11.2010 10:42, Helmut Richter wrote:
> On Tue, 2 Nov 2010, sln@netherlands.com wrote:
>
>> so you can use foreach for readability or 'for' for brevity.
>
> Or "foreach" for lists and "for" for C-style loops. So you see already at
> the keywords what to look for.
sln actually cited perldoc perlsyn.
I only use for, both for lists and for C-style loops, although I don't
remember when I had to use a C-style the last time. Must be long ago.
C-style and list style for look so much different that I don't need two
different keywords for them.
I don't like C-style loops. One reason is that one has to look at the
comparison operator, often it is either < or <=. Sometimes it is hard to
spot if you are off by 1 with an index variable. In C++ there is
BOOST_FOREACH to get something similar to list-style for loops in Perl.
Wolf
------------------------------
Date: Tue, 2 Nov 2010 19:00:35 -0700 (PDT)
From: fl <rxjwg98@gmail.com>
Subject: How to download the complete Perl pdf doc
Message-Id: <265c0f3a-f463-490c-9d9e-979133a6a349@v20g2000yqb.googlegroups.com>
Hi,
I find a book source on Perl on the web. These sources are free. After
I find the link of one chapter, I change the appropriate chapter
number I get the rest of the book. The problem is that I do not know
the link to the front book table part and the reference part. I have
the link here (The last chapter):
http://blob.perl.org/books/beginning-perl/3145_Chap14.pdf
Do you know what means can get the front and the back part of the
book.
Thanks a lot.
------------------------------
Date: Tue, 02 Nov 2010 23:15:45 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to download the complete Perl pdf doc
Message-Id: <slrnid1orl.nri.tadmc@tadbox.sbcglobal.net>
fl <rxjwg98@gmail.com> wrote:
> http://blob.perl.org/books/beginning-perl/3145_Chap14.pdf
^^^^^^^^^^^^^^
^^^^^^^^^^^^^^
> Do you know what means can get the front and the back part of the
> book.
http://lmgtfy.com/?q=beginning+perl
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Wed, 3 Nov 2010 07:49:44 +0800
From: "ela" <ela@yantai.org>
Subject: Re: use of "delete" for hash keys
Message-Id: <iaq82r$js0$1@ijustice.itsc.cuhk.edu.hk>
"Tad McClellan" <tadmc@seesig.invalid> wrote in message
news:slrnid04g0.mai.tadmc@tadbox.sbcglobal.net...
> ela <ela@yantai.org> wrote:
>
> The Posting Guidelines say that you should not quote .sigs,
> yet here you are, quoting sigs.
>
Ok, now finally I understand what a .signature is... sorry for not knowing
what it is before...
>
>> I just posted the exercpt instead of
>> dumping the whole codes and the big data files.
>
> Nobody asked you to dump the whole code or big data files!
>
> You were asked to post a short and complete program that illustrates
> the problem you are having.
>
> (Note how I made a short and complete program for you to run, you
> should be able to do that for us too.
> )
I will strike a good balance from learning this example then.
> If your code reads a file into an array, and that part is working OK,
> then just post code that initializes the array to the same values it
> would have gotten if you read them from a file.
Oh, I see.
>> Another problem that I
>> frequently encounter is that I just don't know what keywords I should use
>> in
>> order to Google/study documentation (In this example, hash array
>> reference
>> doesn't work at all).
>
>
> That is because there ARE NO REFERENCES in the code in this thread.
>
> I can't even remember what your question was anymore...
>
Do "references" mean previous messages? Sorry to look silly, but it's better
to clarify than being misunderstood as misbehaviour...
------------------------------
Date: Tue, 02 Nov 2010 17:02:21 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: use of "delete" for hash keys
Message-Id: <021120101702215264%jimsgibson@gmail.com>
In article <iaq82r$js0$1@ijustice.itsc.cuhk.edu.hk>, ela
<ela@yantai.org> wrote:
> "Tad McClellan" <tadmc@seesig.invalid> wrote in message
> news:slrnid04g0.mai.tadmc@tadbox.sbcglobal.net...
> > ela <ela@yantai.org> wrote:
> >
> >> Another problem that I
> >> frequently encounter is that I just don't know what keywords I should use
> >> in
> >> order to Google/study documentation (In this example, hash array
> >> reference
This ^^^^^^^^^ word is "reference". It is a Perl construct that means a
value that allows access to a hash (anonymous or otherwise).
> >> doesn't work at all).
> >
> >
> > That is because there ARE NO REFERENCES in the code in this thread.
> >
> > I can't even remember what your question was anymore...
> >
>
> Do "references" mean previous messages?
No. You used the word (see above) in the context of Perl references,
which mean indirect access to Perl values.
--
Jim Gibson
------------------------------
Date: Tue, 02 Nov 2010 20:23:00 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: use of "delete" for hash keys
Message-Id: <slrnid1enn.n4k.tadmc@tadbox.sbcglobal.net>
ela <ela@yantai.org> wrote:
>
> "Tad McClellan" <tadmc@seesig.invalid> wrote in message
> news:slrnid04g0.mai.tadmc@tadbox.sbcglobal.net...
>> ela <ela@yantai.org> wrote:
>>
>> The Posting Guidelines say that you should not quote .sigs,
>> yet here you are, quoting sigs.
>>
> Ok, now finally I understand what a .signature is... sorry for not knowing
> what it is before...
When somebody says don't do "foobar", and you don't understand what they
meant, then you post a followup asking what they meant!
Else it looks like you are ignoring their advice.
> Do "references" mean previous messages?
No. The word "references" has a specific meaning in Perl, just
as "while" and "split" have specific meaning in Perl.
perldoc perlreftut
perldoc perlref
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 2 Nov 2010 21:45:23 -0700 (PDT)
From: jwcarlton <jwcarlton@gmail.com>
Subject: Wildcard matching
Message-Id: <e25fd4a9-01e0-415f-a702-439b2aa4c424@v16g2000yqn.googlegroups.com>
I'm trying to find and replace any non-alphanumeric character (or lack
thereof), followed by a specified word, followed by any other non-
alphanumeric character (or lack thereof).
Here's where I am so far, using "jason" as the specified word:
$comment =~ s/(\W)jason(\W)/$1*****$2/i;
Specifically, I want to catch things like " Jason" (notice the opening
whitespace), "<br>Jason!", "***Jason***", and "<br>Jason\n". I'm not
so concerned about underscores, which I understand aren't included in
\W.
Any suggestions?
------------------------------
Date: Wed, 03 Nov 2010 10:03:00 +0100
From: azrazer <dsfqsdf@poupidoup.com>
Subject: Re: Wildcard matching
Message-Id: <iar8g3$omt$1@speranza.aioe.org>
jwcarlton a écrit :
> I'm trying to find and replace any non-alphanumeric character (or lack
> thereof), followed by a specified word, followed by any other non-
> alphanumeric character (or lack thereof).
>
> Here's where I am so far, using "jason" as the specified word:
>
> $comment =~ s/(\W)jason(\W)/$1*****$2/i;
>
> Specifically, I want to catch things like " Jason" (notice the opening
> whitespace), "<br>Jason!", "***Jason***", and "<br>Jason\n". I'm not
> so concerned about underscores, which I understand aren't included in
> \W.
>
> Any suggestions?
Hello,
well i don't know if i understand well what you want to do... but i'll
give a try
if you want that
" Jason" => " *****"
"<br>Jason!" => "<br>*****!"
"***Jason***" => "***********"
"<br>Jason\n" => "<br>*****\n"
then your RE is correct, you just have to add a * quantifier after \W
(since "lack thereof" is OK), don't you ?
Cheers,
azra
------------------------------
Date: Wed, 3 Nov 2010 09:25:23 +0000 (UTC)
From: Willem <willem@snail.stack.nl>
Subject: Re: Wildcard matching
Message-Id: <slrnid2ak3.2ih9.willem@snail.stack.nl>
jwcarlton wrote:
) I'm trying to find and replace any non-alphanumeric character (or lack
) thereof), followed by a specified word, followed by any other non-
) alphanumeric character (or lack thereof).
Wouldn't it be easier to just match word boundaries (you know, with \b )?
) Here's where I am so far, using "jason" as the specified word:
)
) $comment =~ s/(\W)jason(\W)/$1*****$2/i;
$comment =~ s/\bjason\b/*****/gi;
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3196
***************************************