[13035] in Perl-Users-Digest
Perl-Users Digest, Issue: 445 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 11:23:27 1999
Date: Tue, 10 Aug 1999 08:10:14 -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 Tue, 10 Aug 1999 Volume: 9 Number: 445
Today's topics:
Re: POST via Imagemap - How? (Abigail)
RE: Re: pipes and file handles slmlambert@my-deja.com
Re: Re: pipes and file handles (Malcolm Ray)
Re: Reading the Online Documentation? <aqumsieh@matrox.com>
Re: Reading the Online Documentation? (Rob Greenbank)
Re: Reading the Online Documentation? <picaza@chsi.com>
Re: Reading the Online Documentation? (I R A Darth Aggie)
Re: Reading the Online Documentation? (I R A Darth Aggie)
Re: Reading the Online Documentation? (I R A Darth Aggie)
Re: Reading the Online Documentation? <flavell@mail.cern.ch>
Re: Reading the Online Documentation? (Greg Bacon)
require mylib.pl <nead@neadwerx.com>
Re: search and match <sariq@texas.net>
Re: Simple write routine <aqumsieh@matrox.com>
Slight problem with :i in Getopt::Long <mike@crusaders.no>
Re: Slight problem with :i in Getopt::Long (Johan Vromans)
Re: Sorting Backwards <bradw@newbridge.com>
Re: suggestions for CRAP <qwerty@post.utfors.se>
Re: suggestions for CRAP (I R A Darth Aggie)
Re: suggestions for CRAP <sariq@texas.net>
Using Mail::Header and Mail::Internet <cs454@hotmail.com>
Re: Why use Perl when we've got Python?! (Matthew Bafford)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Aug 1999 09:32:56 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: POST via Imagemap - How?
Message-Id: <slrn7r0e09.b9b.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCLXX September MCMXCIII in
<URL:news:37b0ce8b.1531309@news.skynet.be>:
,, Abigail wrote:
,,
,, >Do you really have to contribute to the notion amongst Dutch people
,, >that people from Belgium don't understand any humour?
,,
,, The Dutch would think *everything* is funny. Ooh! A pile of crap!
,, Hahahah!
As long as it doesn't cost money.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 10 Aug 1999 14:05:52 GMT
From: slmlambert@my-deja.com
Subject: RE: Re: pipes and file handles
Message-Id: <7opbjn$bfh$1@nnrp1.deja.com>
> >Ultimate goal - to be able to transfer the value of a scalar to a
> >file on a remote server by using FTP.
> >
> >It has been suggested that I try to do this by using this by using
> >pipes and file handles while using the Net:FTP package.
> >
> >I can use FTP with a file handle, but I am having difficulty in
> >working
> >out how to point the file handle at the scalar as opposed to a
> >file.
> I guess you didn't see my response to this last Friday, then. See:
>
> http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=509577876&fmt=text
Malcom,
Yes I did catch your response, and it seems like a good approach. The
reason for the second post was that I was having a little difficulty
understanding your code.
>my $pid = open(CHILD, '|-');
>die "Error creating child: $!" unless defined $pid;
>
>if ($pid)
>{
> print CHILD $gibberish;
if the opening of the filehandle was successful the string is printed
to the filehandle...and that is the end of the program
> close CHILD or die "Child died: $?";
>}
>else
>{
if the opening of the filehandle was not successful then you open the
ftp connection, and then try to put STDIN. And then that is the end of
the program...
> my $ftp = Net::FTP->new($remote_host)
> or die "ftp connection failed";
> $ftp->login($username, $password)
> or die "ftp login failed";
> $ftp->put(\*STDIN, $remote_filename)
> or die "ftp put failed";
> $ftp->quit;
> exit 0;
>}
I am relatively new to perl so I could be making a complete arse of
myself (and if I am please be kind), but to me that does not seem
loical.
I have tried to play around with the concept but I am having difficulty
getting my head around the piping of a variable to the filehandle.
Thanks,
Simon
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 10 Aug 1999 14:52:11 GMT
From: M.Ray@ulcc.ac.uk (Malcolm Ray)
Subject: Re: Re: pipes and file handles
Message-Id: <slrn7r0f4r.tdh.M.Ray@carlova.ulcc.ac.uk>
On Tue, 10 Aug 1999 14:05:52 GMT, slmlambert@my-deja.com
<slmlambert@my-deja.com> wrote:
>
>> >Ultimate goal - to be able to transfer the value of a scalar to a
>> >file on a remote server by using FTP.
>> >
>> >It has been suggested that I try to do this by using this by using
>> >pipes and file handles while using the Net:FTP package.
>> >
>> >I can use FTP with a file handle, but I am having difficulty in
>> >working
>> >out how to point the file handle at the scalar as opposed to a
>> >file.
>
>
>> I guess you didn't see my response to this last Friday, then. See:
>>
>> http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=509577876&fmt=text
>
>Malcom,
>Yes I did catch your response, and it seems like a good approach. The
>reason for the second post was that I was having a little difficulty
>understanding your code.
What you're missing in your comments below is that opening '|-' is
magic. See perlipc, but I'll attempt to explain.
>>my $pid = open(CHILD, '|-');
>>die "Error creating child: $!" unless defined $pid;
The open attempts to fork. In other words, if it succeeds, there
will now be *two* copies of the program running, in two separate
processes. In the *parent* process, $pid will contain the numeric
process ID of the *child* process, whereas in the child process $pid
will contain zero. If the fork failed, $pid will contain undef, and
we exit.
In addition, a pipe will be opened between the two processes. In the
parent it will be open for writing as filehandle CHILD; in the child
it will be open for reading as STDIN.
>>
>>if ($pid)
>>{
>> print CHILD $gibberish;
>
>if the opening of the filehandle was successful the string is printed
>to the filehandle...and that is the end of the program
This is the parent. We send some data down the pipe to the child, and
then drop through to whatever follows this code snippet.
>> close CHILD or die "Child died: $?";
>>}
>>else
>>{
>if the opening of the filehandle was not successful
Nope: if the open was unsuccessful we've already exited. See the die
above. We get here if $pid is zero, i.e. this is the child process.
>then you open the
>ftp connection, and then try to put STDIN. And then that is the end of
>the program...
Yes, the child exits after closing the ftp connection. The parent
continues.
>> my $ftp = Net::FTP->new($remote_host)
>> or die "ftp connection failed";
>> $ftp->login($username, $password)
>> or die "ftp login failed";
>> $ftp->put(\*STDIN, $remote_filename)
>> or die "ftp put failed";
>> $ftp->quit;
>> exit 0;
>>}
>
>I am relatively new to perl so I could be making a complete arse of
>myself (and if I am please be kind), but to me that does not seem
>loical.
>
>I have tried to play around with the concept but I am having difficulty
>getting my head around the piping of a variable to the filehandle.
This is where I get to say "what happened when you tried it?".
Incidentally, I've been remiss in not commenting on portability.
I suspect that this would *not* work under Windows (of any flavour)
at present, due to its inability to fork processes.
--
Malcolm Ray University of London Computer Centre
------------------------------
Date: Tue, 10 Aug 1999 13:10:31 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Reading the Online Documentation?
Message-Id: <7op8bv$8sa$1@nnrp1.deja.com>
In article <19990809192526.13206.00002830@ng-bj1.aol.com>,
mesarchm@aol.com (Mesarchm) wrote:
> My point is that they obviosly tried the docs and it didn't make
> sense.
You think so? Have you been around here for a while? I don't think so.
Just to show you how ignorant and laZy some people are, here are a
couple of questions I read on clpmisc today.
1) How do you get the return value of a system call?
2) How do you uppercase the first letter of a string?
And here are the relevant citations from the docs:
1) From perldoc -f system:
=item system LIST
Does exactly the same thing as "exec LIST" except that a fork is done
first, and the parent process waits for the child process to complete.
Note that argument processing varies depending on the number of
arguments. The return value is the exit status of the program as
returned by the wait() call. To get the actual exit value divide by
256.
2) From perlfaq4:
How do I capitalize all the words on one line?
To make the first letter of each word upper case:
$line =~ s/\b(\w)/\U$1/g;
As you can see, the docs and FAQs contain answers to 99% of the
questions posted to clpmisc. It is much easier to do a grep on the docs
and search for an answer yourself, than to post to usenet (IMHO). Most
Newbies don't think so. Why? I think they are just too lazy. They don't
want to learn Perl. They want to use Perl to write some application,
without learning it, or evening breaking a sweat.
Do you go around hacking some C code without reading something about C
first? No. But Perl seems to be different as far as newbies are
concerned.
> So people turn here for help. Then a few people who THINK
> they know everything reply to half the messages posted w/ "Read the
> Docs"
That is because they know that the answer lies in the docs. Most of such
replies either refer to the exact piece of doc to be browsed or contains
a small excerpt from the relevant part of the docs. Is this bad advice?
You should be thankful that there are some people that are willing to
guide you for free. Learning to read the docs should be a pre-requisite
to programming.
OTOH, if a question is properly asked, and the poster showed that they
genuinely tried and couldn't get a result, and that the answer is not
lying somewhere in the docs, then you'll get a lot of useful code posted
from some of Perl's best gurus. I guarantee that.
--Ala
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 13:32:14 GMT
From: rob@frii.com (Rob Greenbank)
Subject: Re: Reading the Online Documentation?
Message-Id: <37b0273b.56100156@news.frii.com>
On Tue, 10 Aug 1999 00:26:40 +0200, "Alan J. Flavell" >
>Au contraire, the online documentation is of far more use to them than a
>one-off here. It's the difference between giving them one fish, and
>setting them up for a lifetime's fishing.
>
Ahhh. BEST answer I've seen in ages, in ANY newsgroup!
Very logical -- if one learns to use the documentation properly (and
maybe a book or two) the programs/scripts are finished in a fraction
of the time it takes to get a Usenet reply. This leaves much more
time for fishing! I'd NEVER complain about that!
As Rancid Crabtree (anyone know who that is?) once said: "Only two
times when it's right for fishin'. One's when it's raining. The
other's when it aint!"
Anyway, there's perl apprentices (geez I hate the word "newbe") that
have been pointed to CLPM. Some of them have very little experience
with newsgroups. Sure, they're bound to ask the questions everyone
asks when starting out, and I don't have a problem with those people
as long as they learn from the reply. It's the ones you see asking
beginner questions over and over again, despite being told dozens of
times how to "perldoc". If they can't learn the docs, they'll never
learn perl!
Rob
------------------------------
Date: Tue, 10 Aug 1999 09:39:35 -0400
From: "Peter Icaza" <picaza@chsi.com>
Subject: Re: Reading the Online Documentation?
Message-Id: <7opa2i$uqq$1@pike.uhc.com>
>Why is it that everytime someone asks a question instead of being helpful
> people reply with a "read the online documentation
probably to teach the person to fish rather than giving them a fish! this is
ultimately the best help. i read "learning perl" cover to cover before
even lurking this newgroup. i am now reading "programming perl", "mastering
regular expressions", concurrently. in addtion to (manuals on 68
mustang[a/c and brakes], 63 austin mini[suspension, engine coversion], 98
triumph adventurer motorcycle). personally, i find people more willing to
help you once you have shown you have tried to help yourself. even as a
nubie, (yes i spell foobar as fubar also), i see questions asked that are
well covered in the books. my reply: rtf(ol)m first, then ask.
------------------------------
Date: 10 Aug 1999 13:36:10 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Reading the Online Documentation?
Message-Id: <slrn7r0aqf.3h2.fl_aggie@thepentagon.com>
On 09 Aug 1999 23:25:26 GMT, Mesarchm <mesarchm@aol.com>, in
<19990809192526.13206.00002830@ng-bj1.aol.com> wrote:
+ My point is that they obviosly
Really? how is it obvious? If you've looked, then you should say what
you've tried. Do I really need to repost MJD's article on "How to ask
a good question"?
+ tried the docs and it didn't make sense. So
+ people turn here for help. Then a few people who THINK they know everything
+ reply to half the messages posted w/ "Read the Docs"
I've found many of the answers to my questions in the document set. I
recommend it highly.
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: 10 Aug 1999 13:38:01 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Reading the Online Documentation?
Message-Id: <slrn7r0atu.3h2.fl_aggie@thepentagon.com>
On Tue, 10 Aug 1999 07:28:38 -0400, Elaine -HFB- Ashton
<elaine@chaos.wustl.edu>, in <37B00C96.CE659D14@chaos.wustl.edu>
wrote:
+ I R A Darth Aggie wrote:
+ > So I can insure that they'll be back tomorrow, trolling for another
+ > answer?
+ True, very true, but need you stick the hook in their eye?
And the solution is? I'll cheerfully sit back and wait for an answer.
+ And reading doesn't ensure that one will know how to spell or use the
+ English language properly.
And this relates to perl how?
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: 10 Aug 1999 13:41:36 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Reading the Online Documentation?
Message-Id: <slrn7r0b4l.3h2.fl_aggie@thepentagon.com>
On 09 Aug 1999 23:36:30 GMT, Mesarchm <mesarchm@aol.com>, in
<19990809193630.09549.00004471@ng-bj1.aol.com> wrote:
[about Just Another Larry]
+ He answers 90% of the posts on this newsgroup w/ "Read the Docs"
+ Get a life.
Oh, I get it...and so will you... *plonk*
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Tue, 10 Aug 1999 15:46:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Reading the Online Documentation?
Message-Id: <Pine.HPP.3.95a.990810153830.4609D-100000@hpplus03.cern.ch>
On Tue, 10 Aug 1999, it was written:
> Newbies don't think so.
> Why? I think they are just too lazy.
Not "lazy" in the true sense. They don't want to exercise that grey
matter to the point where they are empowerd to be truly lazy. This is
what the regulars here are trying to teach them.
> They don't want to learn Perl.
There you are, you see. If they were truly lazy, they would want to
learn Perl.
> They want to use Perl to write some application,
They _want_ a free handout, with no strings attached, and without having
to move a grey cell to do it. If the original question wasn't enough
evidence of that, then the inevitable whine-back usually confirms the
suspicion.
The truth is, usenet is a free supply of potentially misleading
suggestions, so they're going to have to move that grey matter anyway,
to evaluate the answers. How much better if they'd do the filtering
before posting, rather than after.
> OTOH, if a question is properly asked, and the poster showed that they
> genuinely tried and couldn't get a result, and that the answer is not
> lying somewhere in the docs, then you'll get a lot of useful code posted
> from some of Perl's best gurus. I guarantee that.
Good advice indeed.
------------------------------
Date: 10 Aug 1999 14:59:08 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Reading the Online Documentation?
Message-Id: <7opens$1tp$1@info2.uah.edu>
In article <19990809181113.04942.00000450@ng-ch1.aol.com>,
mesarchm@aol.com (Mesarchm) writes:
: Why is it that everytime someone asks a question instead of being helpful
: people reply with a "read the online documentation".
How is that unhelpful?
: If you don't want to h
: someone out, don't.
That's generally how it works.
: It is obvious that they are new to perl and need some
: help. Sure you can mention that the docs are a good place to look, but if y
: know the answer give it to them, don't be a ass.
We were all new to Perl once. How do you think the regular answerers
learned? I'll give you a clue: it certainly wasn't by tossing out some
gimme-gimme crap. We (surprise!) read the documentation that comes with
Perl. Your approach scales poorly. If we provided detailed answers to
each and every question that appeared in the group, comp.lang.perl.misc
would quickly become big and useless.
Think of it as Usenet algebra. We're factoring out the common stuff
place instead of distributing it everywhere. By collecting answers to
Frequently Asked Questions, we have one community resource with input
from lots and lots of people. Creating and maintaining a FAQ is a great
deal of work. Ignoring it insults everyone who's ever contributed to
the effort. That's why people become so annoyed when someone has
obviously ignored the FAQ or the docs. (Aside: I wish English had
separate words for inclusive or and exclusive or.)
If someone is having trouble with the docs, then that person should say
I read the documentation in <manpage>. The following code is what
I've tried so far, but it's resulting in <result> instead of
<expected-result>.
<small-code-sample>
Where am I going wrong?
(The above non-terminals should be self-documenting. :-)
In other words, the poster should show that he has actually made an
effort to solve the problem. comp.lang.perl.misc is not a source for
free handouts. While I believe in compassion, there is no such thing
as being down on your luck when it comes to Perl documentation.
Greg
--
Good times and riches and son of a bitches
I've seen more than I can recall.
-- Jimmy Buffett
------------------------------
Date: 10 Aug 1999 14:53:31 GMT
From: "Nick Downey" <nead@neadwerx.com>
Subject: require mylib.pl
Message-Id: <01bee340$308fdfe0$53343d80@r52h83>
The perl cookbook would lead me to believe that perhaps I should learn how
to write a module because the notion of libraries is quickly becoming
obsolete, however, all I want to do is store a mass of strings...
const.pl:
$const_str1 = 'this is string1';
$const_str2 = 'this is string2';
1;
#// const.pl
mytest.pl
#!/usr/bin/perl -w
require 'const.pl';
print "$const_str1\n";
print "$const_str2\n";
#// mytest.pl
Now, if there is anything that I have learned from reading this group it is
that you must use the -w flag. So I use said flag and the following output
is sent to stderr accordingly:
Name "main::const_str1" used only once: possible typo at ./mytest.pl line
5.
Name "main::const_str2" used only once: possible typo at ./mytest.pl line
6.
My question is then: Is there a better way to define a file of (50-60)
constant strings, that is used across several scripts, or should I ignore
the previous lines?
Thanks
------------------------------
Date: Tue, 10 Aug 1999 09:48:40 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: search and match
Message-Id: <37B03BC8.8BA3F805@texas.net>
Christian Evans wrote:
>
> I have a module in a perl script that allows users to search for a record
> with a field that matches a desired date. The dates are in the format with
> the first three letter of the month (i.e. Jan) followed by one OR two
> spaces, and the day of the month. How can I write the script to search for
> all possible records. I have tried many different possible choices and
> can't seem to get any of them to work.
>
> It seems as though when I search, my script will match all records with a
> field with a given month, but I can't seem to match the month and the date
> at the same time.
>
> Thanks
Christian -
You may receive a reply from a certain unmentioned party stating that
there is an 'error in line 17'.
*Don't you believe it!*
The error is on line 21!
Seriously, we can't possibly tell you what's wrong with your code when
we can't see it. Cut-and-paste the smallest possible portion that
illustrates the problem, and you may get some helpful responses.
- Tom
------------------------------
Date: Tue, 10 Aug 1999 08:26:00 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Simple write routine
Message-Id: <x3yyafj7rfr.fsf@tigre.matrox.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Uri Guttman <uri@sysarch.com> wrote in comp.lang.perl.misc:
>
> > $date_file = 'y2kcompatible' ;
> > open( DATE, ">$date_file" ) || die "can't create file $date_file $!" ;
> > print DATE scalar( localtime ), "\n" ;
> > close( DATE ) || die "can't close file $date_file $!" ;
>
> I have rarely seen a check on close of an ordinary file. Is there
> any particular reason why you include it here? Or just general
> tidiness?
IMHO, it is best to check the return value of any Perl function that
has a useful return value. close() is one of them.
But I usually use warn() or die() depending on my program. For
example, if the file associated with the filehandle to be close()d is
to be re-opened again for reading, then I use a die():
close FILE or die "Error closing file: $!\n";
The reason is that if the close() failed, I am not guaranteed to have
correct data in my file once I re-open it. OTOH, if I just want to
close the filehandle and never re-open it again, then I do a
warn(). All filehandles will be closed automatically once my program
ends.
my two cents,
Ala
------------------------------
Date: Tue, 10 Aug 1999 15:22:28 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Slight problem with :i in Getopt::Long
Message-Id: <LIVr3.203$sn1.1999@news1.online.no>
Hi.
I'm using Getopt::Long in a program, and have bumped into a small annoyance.
This is how I call it.
my %opt = ();
my @valid_options = qw/help debug:i verbose trace images! force! xml! all/;
GetOptions (\%opt, @valid_options);
As you can see, debug is the only option that can take an optional integer
argument.
So when i call the program with
./program.pl -help -debug -verbose -trace -images -force -xml -all
then help, verbose, trace, images, force, xml and all in %opt will be set to
1 and $opt{debug} will be set to 0. While it makes sense to me that all the
boolean values are set to 1, I'd really like $opt{debug} to be set to 1 when
it appears among the arguments, instead of 0 which it is now.
From what I can tell from the docs this is a feature, it just happens to be
a feature I don't particularly care for. Anyway - I've made this little
function to get the behavior I prefer (yes, I know I'm modifying
@valid_options with this, but it doesn't matter at the moment)
for (grep s/:i$// => @valid_options)
{$opt{$_} ||= defined $opt{$_} ? 1 : 0}
but I'm left with the feeling that I must have missed a part of the manual
from Getopt::Long.
Another problem with this is of course that it's impossible to set the
option to 0 from the commandline, you have to _not_ use the option to get it
set to 0
Well, I guess the question boils down to: Do I have to scan through the
options like this or did I miss an option from the Getopt::Long manual?
I'm of course also open for suggestions to better ways of translating the
values
--
Trond Michelsen
------------------------------
Date: 10 Aug 1999 15:58:15 +0200
From: JVromans@Squirrel.nl (Johan Vromans)
Subject: Re: Slight problem with :i in Getopt::Long
Message-Id: <wl3lnbjvitk.fsf@plume.nl.compuware.com>
"Trond Michelsen" <mike@crusaders.no> writes:
> but I'm left with the feeling that I must have missed a part of the manual
> from Getopt::Long.
>
> Another problem with this is of course that it's impossible to set the
> option to 0 from the commandline, you have to _not_ use the option to get it
> set to 0
With the current Getopt::Long this is not exactly possible. But if you
make debug take an optional string (instead on integer), you can
discriminate between any values and the empty string. It makes the
GetOptions call a little more complex, but it is an elegant and
powerful solution that is useful in a lot of other situations as well.
GetOptions (%opt, "debug=s" => \&handle_debug, ...)
sub handle_debug {
# Check for numeric (or empty) values.
if ( $_[1] =~ /^\d*$/ ) {
# Assign it. Interpret the empty value as '1'.
$opt{$_[0]} = $_[1] eq '' ? 1 : $_[1];
}
else {
# Signal using 'warn'.
warn ("Value \"$_[1]\" illegal for option \"$_[0]\"".
" (integer value expected)\n");
# This will make the call to GetOptions fail.
$Getopt::Long::error++;
}
}
-- Johan (author and maintainer of Getopt::Long)
------------------------------
Date: 10 Aug 1999 09:50:40 -0400
From: bj <bradw@newbridge.com>
Subject: Re: Sorting Backwards
Message-Id: <op1d7wv7nin.fsf@newbridge.com>
mesarchm@aol.com (Mesarchm) writes:
> I obviously read those and it didn't make sense. I also read the perl cookbook
> p.144 and several other references. If it had made sense I wouldn't be asking
> for help. If you don't know the answer don't reply. If you do, I appreciate
> it.
If you have already read the online documentation, and other reference
material and "don't get it" then _say_ so. In the absence of this
info, people are going to assume you are starting from square one and
thus the most helpful answer will be to point you to the relevant
documentation that deals with your question. Do you see the difference
between "how do I sort backwards" and "I read <blah blah blah> about
reverse sorting and still don't understand the following...."?
It is not the fault of the responders that you did not frame your
question appropriately. Psi::ESP is not a widely distributed module.
bj
--
bradw@newbridge.com Newbridge Networks Corporation
Brad Warkentin 600 March Road, Kanata, Ontario K2K 2E6
CAE Architect (613) 599-3600 ext. 6117 FAX: 599-3654
------------------------------
Date: Mon, 09 Aug 1999 15:17:23 +0200
From: "Dr. Who" <qwerty@post.utfors.se>
Subject: Re: suggestions for CRAP
Message-Id: <37AED4E3.ACD36171@post.utfors.se>
Uri Guttman wrote:
> why are all the free cgi sites full of crappy code? doesn't anyone who
> knows how to use a module publish scripts on the web? is it a requirement
> to have a site of free code to have a room temp iq?
>
All perlmodules are removed(in 99 cases of 100) from webhotels.
You are then forced to write code like that, or it'll fail.
>
> here are some fun examples that pinyan's group can comment upon. some
> general notes:
>
> none use cgi.pm, strict or -w. they are both over and under commented at
> the same time. all have multiline copyrights (as if anyone would want to
> claim this crap as their own).
>
> http://www.datacomm.ch/atair/perlscript/vote.pl
>
> ###Getting http-DATA.
>
> @QueryArray=();
> @QueryKey=();
> %Query=();
>
> why are these initialized and then assigned to?
>
> $QueryString=$ENV{'QUERY_STRING'};
> $client_addr=$ENV{'REMOTE_ADDR'};
> $cookie_string=$ENV{'HTTP_COOKIE'};
> @QueryArray=split '&',$QueryString;
> foreach(@QueryArray){
> ($key, $val) = split ('=',$_);
> $Query{$key} = $val;
> }
> @QueryKey=keys(%Query);
>
> give that guy credit. this isn't cargo cult from matt. he rolled his own
> crap cgi parser.
>
> he uses lower case filehandles, but he does check for open errors. then
> he does dumb stuff like:
>
> if (!open(filehandle1,$config)) {printError("ERROR reading $config\n");}
> while (<filehandle1>) {
> push(@settings,$_);
> }
>
> slurping a whole file may be poor, but the while/push loop is pathetic.
>
> http://bignosebird.com/carchive/survey/survey.txt
>
> this one never checks for open errors but it has upper case file
> handles.
>
> my favorite part is grep_hunt:
>
> sub grep_hunt
> {
> if ( -e "/bin/fgrep")
> {$GREP="/bin/fgrep"; return;}
>
> if ( -e "/bin/grep")
> {$GREP="/bin/grep"; return;}
>
> if ( -e "/usr/bin/grep")
> {$GREP="/usr/bin/grep"; return;}
>
> if ( -e "/sbin/fgrep")
> {$GREP="/sbin/fgrep"; return;}
>
> if ( -e "/usr/sbin/fgrep")
> {$GREP="/usr/sbin/fgrep"; return;}
>
> if ( -e "/usr/bin/fgrep")
> {$GREP="/usr/bin/fgrep"; return;}
>
> if ( -e "/usr/sbin/grep")
> {$GREP="/usr/sbin/grep"; return;}
>
> if ( -e "/sbin/grep")
> {$GREP="/sbin/grep"; return;}
>
> print "Content-type: text/html\n\n";
> print "ERROR! Unable to find grep utility.\n";
>
> does anyone see a potential loop there? besides it being a stupid thing to
> do at runtime.
>
$sdf=`whereis grep`; saves the loop..
>
> http://www.shavenferret.com/scripts/vote/download/vote.cgi
>
> this has my favorite moron code, multiple print statements. why do
> newbies never discover here docs? i also wonder why they think here docs
> are for printing only? it should be documented or xref'ed from the
> literal/quoting sections of the docs.
>
> also it has lots of backwhacked quotes in quotes.
>
> print "<center>Administration<form method=\"POST\"></center>\n";
> print "<table cols=\"2\"><tr><td align=\"right\">Password:</td>\n";
> print "<td><input type=\"password\" name=\"password\"></td></tr></table>\n";
>
> here is a fun section. the open isn't checked but he does a clean slurp
> of the file (which isn't needed). but then, he loops TWICE over the
> lines and splits each line again. also he never learned about +=.
>
> open (FILE, "$data_path/ch$FORM{'topic'}.txt");
> @lines = <FILE>;
> close(FILE);
> $i = 0;
> foreach $line(@lines) {
> ($topic,$votes,$num) = split(/\|/, $line);
> $i = $i + $votes;
> }
> foreach $line(@lines) {
> ($topic,$votes,$num) = split(/\|/, $line);
> if ($i > 0) { $percent = sprintf("%.2f",100 * ($votes / $i)); }
> else { $percent = "NA"; }
> }
>
> oh, well, i am sick of this. does someone know of a decently written
> free cgi script of any sort out there? let alone a repository of them? i
> bet it is because all the decent perl hackers have plenty of real work
> to do or they focus on cpan and the core rather than cgi apps.
>
> maybe we should form a little project to create a web site with quality
> cgi (and other) scripts. if tom can raise support for the power tools
> project, this should be doable too. then we can finally direct folks to
> examples of cgi code we can be proud of. this crap is embarrassing to
> the perl community.
>
> uri
>
> --
> Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
> uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
> Have Perl, Will Travel ----------------------------- http://www.sysarch.com
> The Best Search Engine on the Net ------------- http://www.northernlight.com
> "F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: 10 Aug 1999 14:05:56 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: suggestions for CRAP
Message-Id: <slrn7r0ci9.3h2.fl_aggie@thepentagon.com>
On Mon, 09 Aug 1999 15:17:23 +0200, Dr. Who <qwerty@post.utfors.se>, in
<37AED4E3.ACD36171@post.utfors.se> wrote:
+ All perlmodules are removed(in 99 cases of 100) from webhotels.
+ You are then forced to write code like that, or it'll fail.
Go to a better site.
[an obscene grep finding loop]
+ $sdf=`whereis grep`; saves the loop..
And is completely and thoroughly dependent upon the contents of
$ENV{'PATH'}. This is one for 'perldoc -f grep'...
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Tue, 10 Aug 1999 09:34:28 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: suggestions for CRAP
Message-Id: <37B03874.DB1176EC@texas.net>
Uri Guttman wrote:
>
> why are all the free cgi sites full of crappy code? doesn't anyone who
> knows how to use a module publish scripts on the web? is it a requirement
> to have a site of free code to have a room temp iq?
>
> here are some fun examples that pinyan's group can comment upon. some
> general notes:
<snipped fun examples>
> oh, well, i am sick of this. does someone know of a decently written
> free cgi script of any sort out there? let alone a repository of them? i
> bet it is because all the decent perl hackers have plenty of real work
> to do or they focus on cpan and the core rather than cgi apps.
>
> maybe we should form a little project to create a web site with quality
> cgi (and other) scripts. if tom can raise support for the power tools
> project, this should be doable too. then we can finally direct folks to
> examples of cgi code we can be proud of. this crap is embarrassing to
> the perl community.
>
> uri
This is a terrific idea. I would love the opportunity to contribute
code while being under the watchful eye of the Perl gods. What better
way to improve my skills?
I certainly don't qualify as a reviewer; however, *you* do Uri. Are you
volunteering?
- Tom
------------------------------
Date: Tue, 10 Aug 1999 06:56:46 -0400
From: Doraemon <cs454@hotmail.com>
Subject: Using Mail::Header and Mail::Internet
Message-Id: <37B0056E.1C29C1D@hotmail.com>
Hello Everyone,
Can someone please tell me the syntax of the Mail::Header and
Mail::Internet. I am trying to create a header using Mail::Header, and
then use Mail::Internet to send the email.
I declared the following fields for the header.
$_from_address_
$_to_address_
$_subject_
$_cc_
$_bcc_
I have assigned values to these variables as follow:
my $_from_address_ = "From: Doraemon@japan.co.jp"'
my $_to_address_ = "Someone@somewhere.com"'
my $_subject_ = "Testing";
my $_cc_ = "";
my $_bcc_ = "";
then from what I have read, the syntax for the "new" constructor for
Mail::Header is as follow:
new ( [ARG], [options]), where ARG is optional and it may be a file
descriptor or reference to an array, if this parameter is given, then
the new object will be initialized with headers either from the array or
from the file descriptor; so I did the following:
@email_header = ($_from_address_, $_to_address_, $_cc_, $_bcc_,
$_subject_);
$header = new Mail::Header(@email_header);
Is the array @email_header created correctly? Do I need spaces or
commas to separate each field in the array so that the constructor will
be able to distinguish each field.
After the header was created, I want to create a Mail::Internet object
with the above header. The parameters for the Mail::Internet object is:
new([ARG],[OPTIONS]), where ARG is optional and maybe either a file
descriptor or a ref. to an array. If this parameter is given, the new
object will be initialized with headers either from the array of read
from the file descriptor. The valid OPTIONS include:
Header - The value of this option should be a Mail::Header obj, if
given, Mail::Internet will not attempt to read a mail header from the
ARG
Body - The value of this option should be a ref to an array which
contains the lines for the body of the message, if given, the
Mail::Internet will not attempt to read the body from the ARG.
... and so I did the following to create the Mail::Internet object:
my @_body_ = ("Hello", "Testing");
$internet_message = new Mail::Internet(@email_header, @_body_);
$internet_message->print();
then when I want to print out the header and body to stdout, I couldn't
see anyting.... can someone please explain to me what I have done
wrong....
Thanx
Doraemon
------------------------------
Date: Tue, 10 Aug 1999 14:00:29 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <slrn7r0b2t.b2t.*@dragons.duesouth.net>
Graham:
: In article <slrn7r047k.ac5.*@dragons.duesouth.net>, Matthew Bafford wrote:
: >Ian:
: >: I have been using Python for some time now, I have occasionally looked
: >: at perl, but was but off by its seemingly counter-intuative, and
: >: over-complicated syntax.
[snip]
: >We like Perl, you like Python.
:
: Errr, no actually. You like Perl and aren't open minded enough to
: discuss the merits of alternatives. some of us might like Perl, AND be
: prepared to discuss it's pros and cons with a python programmer, thank
^
: you very much.
The first thing I look for when choosing a new language to learn is its
aesthetic qualities. If I don't like the way a language looks or feels,
I drop it immediately.
I program because I enjoy programming. I may get paid to program, but
that just happens to be a nice extra.
I never bother trying to program in a language that has no appeal to me.
If, after my first few attempts, a language leaves my head spinning, I
drop it.
When you have two languages as similar as Perl and Python, why bother
comparing them? They both have similar capabilities, with almost any
program possible in one language being equally possible in the other [0].
Ian is obviously more geared towards Python than Perl. That is perfectly
fine. But, if Ian doesn't like the language, why even bother posting to
comp.lang.perl.misc? Just because we may be able to list many reasons
why _WE_ think Perl is better than Python, Ian probably won't agree.
And, no matter what reasons we give, Ian will still see the language in
the same way.
: Graham
--Matthew
--
[0] With the possible exception of JAPHs. The last time I tried to feed
one into the python interpreter, it complained of me being a
traitor, and rm -rf'd /usr/local/perl.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 V9 Issue 445
*************************************