[24701] in Perl-Users-Digest
Perl-Users Digest, Issue: 6858 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 12 06:05:45 2004
Date: Thu, 12 Aug 2004 03: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 Thu, 12 Aug 2004 Volume: 10 Number: 6858
Today's topics:
Re: Camel book: why invoke in the manner @{[&whowasi]}? <astewart1@cox.net>
Re: Camel book: why invoke in the manner @{[&whowasi]}? <nobull@mail.com>
Re: Can somebody explain? (Vittal)
Re: favorite perl IDE <jussij@zeusedit.com>
Re: favorite perl IDE 510046470588-0001@t-online.de
Re: favorite perl IDE <spamtrap@dot-app.org>
Re: How to catch CTRL-C in Windows NT cmd.exe??? <kalinaubears@iinet.net.au>
Re: Lookuping IP address using four nameservers at the <patrice.auffret@intranode.com>
LWP & Javascript <rosyling2004@yahoo.com>
Re: My own handy Pocket Reference notes (please share y <tadmc@augustmail.com>
Re: My own handy Pocket Reference notes (please share y <invalid-email@rochester.rr.com>
Re: My own handy Pocket Reference notes (please share y <nobull@mail.com>
Re: My own handy Pocket Reference notes (please share y (David Filmer)
Re: My own handy Pocket Reference notes (please share y (David Filmer)
Re: My own handy Pocket Reference notes (please share y (Anno Siegel)
Re: Parsing form POST without CGI.pm on Win32 (krakle)
Re: Parsing form POST without CGI.pm on Win32 <spamtrap@dot-app.org>
Parsing html by XML::libXML (John7481)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Aug 2004 18:13:09 -0700
From: Alan Stewart <astewart1@cox.net>
Subject: Re: Camel book: why invoke in the manner @{[&whowasi]}?
Message-Id: <97glh05fl4gcv21c8d3eha9edq58fa5ocs@4ax.com>
On Wed, 11 Aug 2004 22:01:57 GMT, "Suresh Govindachar"
<initiallast-name@yahoo.xyz> wrote:
>#!/use/bin/perl
>BEGIN {(*STDERR = *STDOUT) || die;}
>use diagnostics;
>use warnings;
>use strict;
>
>=head
>Hello,
>
>In the 'Tying Hashes' section of the Camel book (pg 378+),
>a subroutine called whowasi is invoked in the
>following two ways,
>
> 1) @{[&whowasi]}
>and 2) &whowasi
>
>I could not figure out what the first method of
>invocation does and so wrote this code to see
>the difference in results. But I find no
>difference in the results of the two invocations!
>(The output is given below after the __END__.)
>
>Please explain what the first method of invocation
>is all about.
>
>Thanks,
>
>--Suresh
>=cut
>
>use Carp;
>sub whowasi { (caller(1))[3] . "()" }
>my $DEBUG = 0;
>sub debug { $DEBUG = @_ ? shift : 1 }
>
>sub the_place
>{
> print "\n",'carp "usage: @{[ &whowasi ]} [USER [DOTDIR]]";',"\n";
> carp "usage: @{[ &whowasi ]} [USER [DOTDIR]]";
Interpolated into a string.
>
> print "\n", 'carp "@{[&whowasi]}: ";', "\n";
> carp "@{[&whowasi]}: ";
Interpolated.
>
> print "\n", 'carp &whowasi if $DEBUG;' ,"\n";
> carp &whowasi if $DEBUG;
Not interpolated.
>
> debug();
> print "\nafter setting DEBUG:\n";
> carp &whowasi if $DEBUG;
Not interpolated.
>
> print "\n",'croak "usage: @{[ &whowasi ]} [USER [DOTDIR]]";',"\n";
> croak "usage: @{[ &whowasi ]} [USER [DOTDIR]]";
> print "\nshould NOT see this\n";
>}
>
>sub the_caller
>{
> the_place(53);
>}
>
>sub the_sub
>{
> the_caller();
>}
>
>print "in main:\n";
>the_sub();
>
>__END__
Variables will interpolate into strings but functions will not. This
is a well known trick to get a function into a quoted string.
Functions will execute to get the value of an item in a list, so
[$whowasi] produces an anonymous list reference which is de-referenced
by @{ } to an array that will interpolate.
Back up a page to Camel pg 377 for the other way !
Alan
------------------------------
Date: Thu, 12 Aug 2004 07:37:13 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Camel book: why invoke in the manner @{[&whowasi]}?
Message-Id: <cff36q$f6$1@slavica.ukpost.com>
Suresh Govindachar wrote:
> In the 'Tying Hashes' section of the Camel book (pg 378+),
> a subroutine called whowasi is invoked in the
> following two ways,
>
> 1) @{[&whowasi]}
> and 2) &whowasi
Function calls do not interpolate into double-quoted strings so if you
want to put the result of a function call into the middle a string you
can either use explicit concatenation or use the @{[...]} trick.
See FAQ: How do I expand function calls in a string?
If you ever see the @{[ somefunc ]} construct not in an interpolative
context then it may be being used for it's other effect of 'uncoupling'
values in the situation where somefunc returns lvalues.
Calling the function call syntax with a leading & and without any ()
supresses all the @_ handling. The @_ seen inside the whowasi function
is the caller's @_. (See perlsub). This is occasionaly really useful
in advanced programming but more often is just done as a (possibly
premature) optomisation or through ignorance.
------------------------------
Date: 12 Aug 2004 00:24:19 -0700
From: vsnadagouda@yahoo.com (Vittal)
Subject: Re: Can somebody explain?
Message-Id: <f9dcc290.0408112324.dd29694@posting.google.com>
Hello Jean,
Thank you very much for replying in deatil.
Yes, the person who has written the code has not give much comments
other than saying "matches the parenthesis".
I tried to break the two statements in samller chunks but could not.
These two statements took my night sleep away :-)
Now I have got little understanding about these lines.
Thanks again!
-Vittal
jl_post@hotmail.com (J. Romano) wrote in message news:<b893f5d4.0408110614.683494a8@posting.google.com>...
> vsnadagouda@yahoo.com (Vittal) wrote in message news:<f9dcc290.0408092327.b0120e6@posting.google.com>...
> >
> > In one of the file I found the following snippet:
> >
> > $temp = qr{
> > \(
> > (?:
> > (?>[^()]+ )
> > |
> > (??{ $temp })
> > )*
> > \)
> > }x;
> >
> > $cchat = qr/((\W)?(\*?\*?\w+)\s*($temp))/;
> >
> > Can somebody explain me what these two lines do?
>
> Dear Vittal,
>
> The good news is that the programmer who wrote that script did not
> create the first line him/herself. He/She just copied it straight
> from the "prelre" documentation. To read what it does, type "perldoc
> perlre" at a DOS or Unix prompt and search for the word "postponed".
> You'll see the exact same piece of code and the explanation that this
> regular expression matches a parenthesized group.
>
> In other words, if you can use $temp like this:
>
> if ("I saw a color (blue)." =~ m/$temp/)
> {
> print $&; # this prints the match "(blue)"
> }
>
> It will also work with nested parentheses, like this:
>
> if ("I already ate (I ate one (1) pizza)." =~ m/$temp/)
> {
> print $&; # this prints "(I ate one (1) pizza)"
> }
>
> The bad news is that the programmer who wrote that script didn't feel
> the need to add comments to explain the purpose of those regular
> expressions. It has been said that it's almost always easier to
> create your own regular expressions than to understand one that's
> already written, and in this case that's definitely true. If it
> wasn't for the fact that the first line was specifically mentioned in
> "perldoc perlre", I'm sure that I would not have been able to figure
> out what it was looking for.
>
> The second regular expression is a little easier to figure out.
> Let's take it a bit at a time:
>
> > $cchat = qr/((\W)?(\*?\*?\w+)\s*($temp))/;
>
> The only parts of the $cchat regular expression that are not optional
> are the \w+ part (which matches at least one "word" character (that
> is, a letter, digit, or underscore)) and $temp, which matches a
> parenthesized expression. Optionally, there may be whitespace (any
> amount) between the non-optional parts. Also, there may be one or two
> asterisks before the \w+ part. There could also be an optional
> non-"word" character before the word characters (which would appear
> before the asterisks, if the asterisks happen to exist).
>
> Was my explanation confusing? If you didn't think so, then you're
> a super genuis. I didn't expect it to be very easy to follow (like it
> is said, it's not very easy to understand a regular expression that
> you didn't write), so I always recommend writing a few comments (with
> any non-simple regular expression) that shows a few sample matches.
> The writer of that program you're reading should have included a few
> comments like this:
>
> # The $temp regular expression was taken right out of
> # the "perldoc perlre" documentation. It matches a
> # parenthesized expression (that may or may not contain
> # nested parentheses):
> $ temp = ... ;
>
> # The purpose of the $cchat regular expression is ...
> # It matches all of the following lines:
> # some_text(parenthesized expression)
> # some_text (parenthesized expression)
> # *some_text(parenthesized expression)
> # **some_text (parenthesized expression)
> # %*some_text (parenthesized expression)
> # ^**some_text(parenthesized expression)
> # &some_text (parenthesized expression)
> # !some_text(parenthesized expression)
> $cchat = qr/((\W)?(\*?\*?\w+)\s*($temp))/;
>
> Because the original programmer didn't explain the purpose of the
> $cchat regular expression, it's difficult for us to figure it out for
> sure. The closest we can come to figuring it out is to examine sample
> matches and deduce the purpose from there.
>
> If you ever add more code to this program, do yourself and the
> future maintainers of the program a favor and add comments to document
> your regular expressions. Include the purpose of the regular
> expression (in plain English or whatever language is the main language
> spoken at work) and include a few sample matches (because sometimes
> looking at sample matches helps a person understand much better than
> looking at the regular expression itself). It also helps the
> debugging process a lot.
>
> When you write code, please put comments in your code that explains
> to anyone who didn't write the code what the code is doing and its
> purpose. A lot of coders avoid doing this, giving many excuses as to
> why they shouldn't. Some of the excuses are:
>
> * I don't need to include comments because I write
> non-esoteric (simple) code that anyone can understand.
>
> * Comments eventually become outdated (and outdated comments
> are wrong) and wrong comments are worse than no comments
> at all (because they are misleading).
>
> * I don't need to include comments because I write
> "self-documenting" code. Comments are a sign that the
> code is impossible to understand without outside help,
> and I don't write code like that.
>
> Don't fall into those traps! I may be offending some die-hard
> programmers here who adhere to one or more of the above traps I
> listed, but I sincerely believe that comments and documentation are
> vital to writing programs (especially when writing programs that will
> be read by other people) -- even if the comments and documentation
> become outdated (outdated comments and documentation may not be
> correct in everything they say, but at least they provide important
> hints to anyone trying to understand, debug, and maintain the code).
>
> I hope this helps, Vittal.
>
> -- Jean-Luc Romano
------------------------------
Date: Thu, 12 Aug 2004 16:24:37 +1000
From: Jussi Jumppanen <jussij@zeusedit.com>
Subject: Re: favorite perl IDE
Message-Id: <411B0D25.F8F@zeusedit.com>
dragonbide wrote:
> Hi. I'm looking for a good perl IDE. What are some of your
> favorites? (preferably for windows, but list whatever ones you'd
> like) .
Take a look at Zeus for Windows:
http://www.zeusedit.com/lookmain.html
Some the features include:
+ Code completion and intellisensing
+ Integrated class browser
+ Project/workspace management
+ Fully configurable syntax highlighting
+ Seamless FTP editing
+ Integrated version control using the Microsoft Source Code
Control (SCC) interface, including CVS integration.
+ Quick Help context sensitive help engine
Jussi Jumppanen
http://www.zeusedit.com
------------------------------
Date: 12 Aug 2004 08:29:21 +0200
From: 510046470588-0001@t-online.de
Subject: Re: favorite perl IDE
Message-Id: <874qn898e6.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me>
Abigail <abigail@abigail.nl> writes:
> dragonbide (allen.jordan@colorado.edu) wrote on MMMCMXCVIII September
> MCMXCIII in <URL:news:d5ef4ee9.0408110712.2517dd10@posting.google.com>:
> :: Hi. I'm looking for a good perl IDE. What are some of your
> :: favorites? (preferably for windows, but list whatever ones you'd
> :: like) .
the GNU Emacs, of course
Klaus Schilling
------------------------------
Date: Thu, 12 Aug 2004 04:33:55 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: favorite perl IDE
Message-Id: <nZidndzlSIXutobcRVn-tA@adelphia.com>
dragonbide wrote:
> Hi. I'm looking for a good perl IDE. What are some of your
> favorites? (preferably for windows, but list whatever ones you'd
> like) .
Project Builder & BBEdit. ;-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Thu, 12 Aug 2004 15:49:59 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: How to catch CTRL-C in Windows NT cmd.exe???
Message-Id: <411b063c$0$16324$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Solo wrote:
> I wrote the following code just to test the catch of Ctrl-C:
> ---------------
>
> {
>
> $SIG{'INT'} = \&cmd1;
>
>
> print "Entering the loop \n\n";
> while (1)
> {
> }
>
> }
>
> sub cmd1
> {
> my ($sig) = @_;
> print "The Interrupt was caught: <$sig>\n";
> exit (0);
> }
>
> --------------------
> It works perfectly on UNIX, But in the windows NT cmd.exe or 4NT prompt, it
> just kills the process and does not display the print message...
>
> HELP!!!
It works fine for me in a cmd.exe shell on Windows 2000, and displays
the print message. Is that a copy'n'paste of the actual program that's
failing on NT ?
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Thu, 12 Aug 2004 09:16:06 +0200
From: Patrice Auffret <patrice.auffret@intranode.com>
Subject: Re: Lookuping IP address using four nameservers at the same time.
Message-Id: <20040812091606.09fe5fbe.patrice.auffret@intranode.com>
On Thu, 05 Aug 2004 14:40:23 +0200
Tom Regner <regner@dievision.de> wrote:
[..]
> for (@children) {waitpid($_, 0);}
[..]
You can put a signal handler in parent process to avoid waitpid()
(since returned status is ignored).
$SIG{CHLD} = 'IGNORE';
------------------------------
Date: Thu, 12 Aug 2004 00:56:35 -0400
From: "Perly" <rosyling2004@yahoo.com>
Subject: LWP & Javascript
Message-Id: <297c26f13a7018b197dd5cae3570900e@localhost.talkaboutprogramming.com>
Hi Everyone,
I want to know if there's any perl module that can handle submitting
javascripted form..
------------------------------
Date: Wed, 11 Aug 2004 21:33:12 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <slrnchlln7.8a5.tadmc@magna.augustmail.com>
David Filmer <IneverReadAnythingSentToMe@hotmail.com> wrote:
> Do you have some handy notes scratched inside YOUR Perl book? Maybe
> you can share them also.
>======================================================================
> Instead of: $answer = $var1 . func() . $var2; #Perl CookBook 1ed p.21
> $answer="$var1 ${\( SCALAR EXPR )} $var2"; #ie:"eat ${\($n+1)} pie"
>
> $answer = "$var1 @{[ LIST EXPR ]} $var2";
I would prefer the original.
It isn't too painful and has much less potential for "startle factor".
I tend to format it so as to make it easy to see what's going on:
$answer = $var1
. func()
. $var2;
>======================================================================
> To embed a variable in a variable name (maybe bad practice):
^^^^^
The "maybe" is ill advised unless you are a Perl expert and know
why you must use symrefs this time.
Symref use can almost always be replaced with either a real
reference or with a hash data structure (or both).
>======================================================================
> To prevent output from being buffered:
> select(STDERR); $| = 1; select(STDOUT); $| = 1;
To enable auto-flushing:
or
To simulate no buffering:
would be accurate.
$| does not disable buffering, it enable auto-flush. The filehandle
is still buffered (but the buffer gets flushed a lot more often).
(and STDERR is usually unbuffered anyway)
> print map { $_->[0] } #Randall Schwartz Rocks!!!
He even named his company after rocks.
What a guy!
(but his name is spelled "Randal")
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 12 Aug 2004 02:50:56 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <411ADB0F.3000702@rochester.rr.com>
David Filmer wrote:
...
> ======================================================================
> Schwartzian Transform: For example, to sort /etc/passwd file by fields
> print map { $_->[0] } #Randall Schwartz Rocks!!!
> sort { $a->[1] <=> $b->[1] #numerically sort first by gid
> || $a->[2] <=> $b->[2] #numerically sort second by uid
> || $a->[3] <=> $b->[3] #alphabedic sort by loginID last
cmp-----------------------^^^
> } map { [ $_, (split /:/)[3,2,0] ] } `cat /etc/passwd`;
> ======================================================================
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Thu, 12 Aug 2004 07:52:31 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <cff43f$ha$1@slavica.ukpost.com>
David Filmer wrote:
> Instead of: $answer = $var1 . func() . $var2; #Perl CookBook 1ed p.21
> $answer="$var1 ${\( SCALAR EXPR )} $var2"; #ie:"eat ${\($n+1)} pie"
For the third time in 24 hours....
Please will people stop promulgating this broken constuct. I eventually
managed to get it withdrawn from perlfaq4 but it still seems to pop up a
lot.
${\(EXPR)} does not evaluate EXPR in a scalar context. It evaluates it
in a list context and then discards all but the last value. This is
actually a slight simplification - the context in which EXPR is not
quite a normal list context. (For details read about the \ operator).
> $answer = "$var1 @{[ LIST EXPR ]} $var2";
Use this for scalars (actually single value lists) too. I realise
there's a slight overhead of creating a temporary array but I think the
gain in clarity is worth it. If you need to force a scalar context then
do so explicitly @{[ scalar EXPR ]}.
------------------------------
Date: 12 Aug 2004 01:20:19 -0700
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <e4c916dd.0408120020.16e1be8d@posting.google.com>
Thanks, Tad/Bob, for your input (and especially Bob for catching that
code error in the Schwartzian Transform! It was written correctly in
my book but transcribed incorrectly in my usenet post! OOPS!). I will
wait for other input and then post a corrected version per this input.
Additional notes are welcome!
------------------------------
Date: 12 Aug 2004 01:41:07 -0700
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <e4c916dd.0408120041.64a201d@posting.google.com>
OOPS, I just noticed another transcription error:
>> ==================================================================
>>To generate a random integer between 0 and 10 (inclusive):
>> $foo = rand(11); #or rand(10)+1 if between 1 and 10 inclusive
>> ==================================================================
I didn't include the 'int' operator. This SHOULD say:
======================================================================
To generate a random integer between 0 and 10 (inclusive):
$foo = int rand(11); #or int rand(10)+1 between 1 and 10 inclusive
======================================================================
Again, I will wait for additional feedback and post corrected version.
------------------------------
Date: 12 Aug 2004 10:00:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <cfff46$3ht$1@mamenchi.zrz.TU-Berlin.DE>
David Filmer <IneverReadAnythingSentToMe@hotmail.com> wrote in comp.lang.perl.misc:
> Over the past couple of years, I have made many little notes inside
> the covers of my O'Reilly Perl Pocket Reference - mostly syntax
[...]
> To strip the path from a filename (such as $0) w/o File::Basename:
> print ($0 =~ /^.\/(.*)/)[0];
This one doesn't compile, and the pattern is way off the mark.
print $0 =~ m{([^/]*)$}, "\n";
Anno
------------------------------
Date: 11 Aug 2004 22:51:08 -0700
From: krakle@visto.com (krakle)
Subject: Re: Parsing form POST without CGI.pm on Win32
Message-Id: <237aaff8.0408112151.60da1782@posting.google.com>
"Aaron DeLoach" <aaron@deloachcorp.com> wrote in message news:<adGdnV6oBaRq1JDcRVn-uQ@eatel.net>...
> Is anyone getting to STDIN using Win XP *Home Version* ? I'm beginning to
> believe it might not be available in the home version.
By that comment i'm sure we now assume you are very new indeed...
Am I the only one who rolled their eyes?
------------------------------
Date: Thu, 12 Aug 2004 04:32:13 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Parsing form POST without CGI.pm on Win32
Message-Id: <nZidnd3lSIWQtobcRVn-tA@adelphia.com>
krakle wrote:
> Am I the only one who rolled their eyes?
No, but you're a bit late to the party - the solution was identified as
a browser bug over a week ago.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 12 Aug 2004 01:59:32 -0700
From: arjohn7481@hotmail.com (John7481)
Subject: Parsing html by XML::libXML
Message-Id: <78ec1629.0408120059.63d3a1c9@posting.google.com>
Hello everybody,
A database project is targeted to use a perl script to parse the html
file and picking few items from html file, it will insert those items
into database.
Could somebody explain their ideas or real experiences to do such
parsing job using libXML?
Thanks in advance
AR
------------------------------
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 6858
***************************************