[17368] in Perl-Users-Digest
Perl-Users Digest, Issue: 4790 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 03:05:35 2000
Date: Thu, 2 Nov 2000 00:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973152311-v9-i4790@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 2 Nov 2000 Volume: 9 Number: 4790
Today's topics:
Re: [OT] Spherical cows (Eric Bohlman)
Re: A Simpler perlish way <hurrian@yahoo.com>
Re: CGI Perl vs. Java Servlets... (Logan Shaw)
Re: CGI Perl vs. Java Servlets... (Logan Shaw)
Re: Hardwood Website <mhumm@ba-mosbach.de>
Re: i'm in 'use vars' hell <mcdonabNO@SPAMyahoo.com>
Re: i'm in 'use vars' hell (Tad McClellan)
Re: Keeping a List of Objects (Eric Bohlman)
Mail::Sender crashes cgi (Jason Goodrow)
Need suggestions on optimization <newspost@coppit.org>
Re: Need suggestions on optimization (brian d foy)
Re: newbie--Sorting pairs by value <MBalenger@worldnet.att.net>
Re: OT: Yes there _are_ stupid questions. Anyone colle <rick.delaney@home.com>
Re: OT: Yes there _are_ stupid questions. Anyone colle (Martien Verbruggen)
Re: Perl Question (Tad McClellan)
Re: Perl Question (Tad McClellan)
Re: Perl Question <james@NOSPAM.demon.co.uk>
Re: Perl Question <james@NOSPAM.demon.co.uk>
Re: Perl Question (Tad McClellan)
Re: Perl style and module searches <philipg@atl.mediaone.net>
Re: Quick question - Still new at this ! msalerno@my-deja.com
Re: regular expression <bart.lateur@skynet.be>
Re: Spaces to tab <MBalenger@worldnet.att.net>
Re: Spaces to tab <MBalenger@worldnet.att.net>
Re: Stultiloquent Queries (was: even or odd?) (Tad McClellan)
Re: Using 'format' and 'write' multiple times? (Eric Bohlman)
Re: Want to process all files less than 24 hours old (Tad McClellan)
Re: Want to process all files less than 24 hours old <mark-lists@webstylists.com>
Re: Want to process all files less than 24 hours old (Tom Christiansen)
Re: Want to process all files less than 24 hours old (Tom Christiansen)
Re: What about CGI.pm? <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Nov 2000 06:04:52 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: [OT] Spherical cows
Message-Id: <8tr064$1b5a$4@news.enteract.com>
Jon Bell <jtbell@presby.edu> wrote:
> The version of the story I heard, as an undergraduate physics major over
> 25 years ago, involved a dairy cooperative that wanted to increase milk
> production. For whatever reason, they decided to call in a
> theoretical physicist as a consultant. After several weeks of work, he
> gave a presentation which began "To simplify our calculations, we will
> assume a spherical cow of uniform density..."
I used to have a compilation volume of the _Journal of Irreproducible
Results_ which included a "paper" in which the author designed a better
mousetrap by changing the specifications for the mouse.
------------------------------
Date: Wed, 01 Nov 2000 15:07:49 -0500
From: Hurrian <hurrian@yahoo.com>
Subject: Re: A Simpler perlish way
Message-Id: <3A007815.38A2D3D8@yahoo.com>
Martien Verbruggen wrote:
> On Tue, 24 Oct 2000 14:43:14 -0400,
> Jody Fedor <Jodyman@usa.net> wrote:
> >
> > Bart Lateur wrote in message <49fhusk7mbm0ejsu395g8f99mgr6am2u8n@4ax.com>...
> > >Jody Fedor wrote:
> > >
> {...}
> > I assume 2096 is a leap year, then why not 2100? It is four
> > years later?
> >
> > 2096/4 = 524
> > 2096/100 = 20.96
> > 2096/400 = 5.24
> >
> > 2100/4 = 525
> > 2100/100 = 21 (Shouldn't be a leap year)
> > 2100/400 = 5.25
> >
> > Doesn't leap year come every 4 years no matter what? Help here.
>
> Did you read the above?
>
> A leap year does not come every four years, no matter what. It comes on
> all years that are divisible by 4, except when they are also divisible
> by 100, but again when it is also divisible by 400.
> {...}
if ( ($yrarg % 100) == 0 ) { return ( ( $yrarg % 400 ) == 0 ); }
else { return ( ( $yrarg % 4 ) == 0 ); }
--
Hurrian
--
------------------------------
Date: 1 Nov 2000 23:08:40 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: CGI Perl vs. Java Servlets...
Message-Id: <8tqsso$cem$1@provolone.cs.utexas.edu>
In article <8tn5el$79o$1@nnrp1.deja.com>, <desarollador@my-deja.com> wrote:
>Could it be that perhaps no one wants to admit the fact that something
>could be faster than Perl?
I don't mind admitting it. Lots of things are faster than Perl.
For instance, very carefully hand-coded RISC assembly is lots faster
than Perl.
The question is what the best tool for the job is.
- Logan
------------------------------
Date: 2 Nov 2000 00:52:24 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: CGI Perl vs. Java Servlets...
Message-Id: <8tr2v8$cqb$1@provolone.cs.utexas.edu>
In article <3A007BB3.DACFF8CF@who.net>, jesus X <jesusx@who.net> wrote:
>"Randal L. Schwartz" wrote:
>> Sorta like that old phrase, "Presume a perfectly spherical cow..."
>
>Ok, I must admit, I don't know this old phrase. I'd love to hear the rest
>though, as the idea of a spherical cow has me rolling in laughter. =-]
For this and many, many other geeky science and engineering jokes, have
a look at http://www.xs4all.nl/~jcdverha/scijokes/ . Section 6 is the
one that has the spherical cow.
- Logan
------------------------------
Date: Thu, 02 Nov 2000 08:26:50 +0100
From: Markus Humm <mhumm@ba-mosbach.de>
Subject: Re: Hardwood Website
Message-Id: <3A01173A.2C12D2BB@ba-mosbach.de>
cfd wrote:
>
> Hardwood floors and more! See the natural beauty of hardwood flooring and hardwood designs at www.classicdistributors.com or http://209.35.59.31!
why do you post that here?
NO ONE HERE IS INTERESTED IN THAT!!!
------------------------------
Date: Wed, 1 Nov 2000 21:23:15 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: i'm in 'use vars' hell
Message-Id: <ZT6M5.11969$Wq1.7746546@nnrp5-w.sbc.net>
> > my objection to the giant hash is that it seems like an extraordinarily
> > strange data structure to have to concoct in order to include global
> > variable declarations from another place.
>
> If you regard a hash as a strange data structure, I'm not sure you will
> ever go very far with Perl.
>
not strange, in and of itself... just strange in the sense of the purpose i
mentioned.
otherwise, thank you.
------------------------------
Date: Thu, 2 Nov 2000 00:41:35 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: i'm in 'use vars' hell
Message-Id: <slrn901vkf.dfq.tadmc@magna.metronet.com>
On Wed, 1 Nov 2000 20:27:51 -0800, Brian McDonald
<mcdonabNO@SPAMyahoo.com> wrote:
>
>"Jeff Zucker" <jeff@vpservices.com> wrote in message
>> Brian McDonald wrote:
>> >
>> > what method will allow me to *not* have to explicitly name every
>variable in
>> > the 'use vars' declaration? ...a method that does not require me to
>create a
>> > single global variable by way of a hash?
>what is the preferred perl solution to this problem?
The preferred _perl_ solution (as opposed to a Perl solution)
is obviously to use a hash, because that _is_ what perl
(the interpreter) uses :-)
If you have globals, then they _will_ be in a hash. They
can be in perl's hash or your own hash, but they're gonna
be in a hash somewhere.
But "perl's hash" can get accessed in funky ways (eg. sym refs).
It's safer to have your own hash where only "normal" hash
access can happen.
Read up on "perl's hash" if you like. See the "Symbol Tables"
section in perlmod.pod.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Nov 2000 06:25:52 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Keeping a List of Objects
Message-Id: <8tr1dg$1b5a$5@news.enteract.com>
Uri Guttman <uri@sysarch.com> wrote:
> i have a similar problem with callbacks and the objects they callback
> both needing refs to each other thereby generating a cycle. i force the
> use of explicit shutdown calls which break the cycles.
IIRC Matt Sergeant had a similar problem when writing XML::XPath: his node
objects needed to contain references to their parents, which in turn had
to contain references to their children. IIRC he used a fairly fancy
system of proxy objects to get out of the bind.
------------------------------
Date: 2 Nov 2000 02:48:49 -0500
From: goodrow@panix.com (Jason Goodrow)
Subject: Mail::Sender crashes cgi
Message-Id: <8tr691$7f7$1@panix2.panix.com>
I'm trying to automate the sending of attachments with Mail::Sender from cpan.
but ...
The addition of
use lib '/net/u/1/g/goodrow/include/Mail-Sender-0.7.04/blib/lib';
use Mail::Sender;
crashes when accessed by a GET - works fine from command line.
I've taken cgi.pm out and pinpointed the addition of those lines.
any help -
thanks
goodrow@panix.com
------------------------------
Date: Thu, 2 Nov 2000 01:16:11 -0500
From: David Coppit <newspost@coppit.org>
Subject: Need suggestions on optimization
Message-Id: <Pine.GSO.4.21.0011020046180.13064-100000@mamba.cs.Virginia.EDU>
Hi all,
I was wondering if anyone had some suggestions for me on optimizing
some code. The applications is called "grepmail", and it basically
does a sequential search through a mailbox looking for emails that
match a pattern. (http://grepmail.sourceforge.net/)
I've already revamped the algorithm so that it only reads anything
from disk once instead of backtracking. I've also added the /o
modifier where appropriate, experimented with study (without success),
switched to reading whole paragraphs, perused Chapter 8 of the camel
book, and done profiling (see below).
Here's the basic algorithm:
while (!eof($fileHandle))
{
get header unless a buffered one exists;
if (the header matches the pattern)
{
get the rest of the email and print it, buffering the header for
the next email;
next;
}
get the rest of the email, buffering the header for the next email;
if (the body matches the pattern)
{
print the header and body;
}
}
I've left out a lot of details, such as the ability to do a quick
decision if the user specifies that the header must match the pattern.
I've used DProf and SmallProf to profile the code. It spends 15% of
its time on the line where the paragraphs of the email body are read,
and 32% of it's time on the line where the body is compared to the
pattern. The rest of the lines of code use less than .02% of the time.
This seems to indicate to me that the script isn't wasting time doing
non-essential stuff...
Questions:
- Is there a faster way to read from the file than setting $/ to
"\n\n"? Should I read in fixed-size chunks, and deal with the
difficulties? (This may help things because huge MIME paragraphs get
read into memory with the current scheme.)
- Is there a faster way to search the body for a match than this:
$matchesBody = ($body_buffer =~ /$pattern/om) || 0;
I thought of searching for a match at the same time as searching for
the next header while reading the body in, but a prototype seemed to
indicate that /(\n^From |$pattern)/ would be really slow.
Any other ideas/suggestions?
Thanks,
David
--
No offense, but please keep any patronization to a minimum. :)
------------------------------
Date: Thu, 02 Nov 2000 01:56:27 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Need suggestions on optimization
Message-Id: <brian-ya02408000R0211000156270001@news.panix.com>
In article <Pine.GSO.4.21.0011020046180.13064-100000@mamba.cs.Virginia.EDU>, David Coppit <newspost@coppit.org> posted:
> I was wondering if anyone had some suggestions for me on optimizing
> some code.
profile the code and think about the slow bits first. :)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Thu, 02 Nov 2000 06:30:08 GMT
From: "Michael Balenger" <MBalenger@worldnet.att.net>
Subject: Re: newbie--Sorting pairs by value
Message-Id: <QR7M5.17389$xJ4.826204@bgtnsc06-news.ops.worldnet.att.net>
> I want to sort the pairs ascending by the number value.
> I tried reversing key/values in the hash, but then obviously you can't
> have two hash keys of the same "name". I just can't picture the
> necessary algorithm. Any suggestions?
Your hunch of a reverse hash was correct. You've just gotta' build a list
as the value since multiple values in the reverse hash will have the same
key.
#!/bin/perl -w
my %happy_factor = (
apple => 10,
banana => 30,
cake => 20,
drinks => 20,
eggs => 50
);
# A reverse hash from %happy_factor.
my %food;
# Repeating the data is the hard way to do this. Notice that the
# vaues are list references. Notice also, that there's no order to
# the keys, or the values witin the value lists.
my %food_the_hard_way = (
20 => [qw(drinks cake)],
10 => [qw(apple)],
50 => [qw(eggs)],
30 => [qw(banana)],
);
# Scalars to hold values from the hashes.
my ($food, $happy_factor);
while ( ($food, $happy_factor) = each %happy_factor ) {
# The value is a list reference. Push the food onto the
# referenced list.
push @{$food{$happy_factor}}, $food;
}
foreach $happy_factor (sort {$a<=>$b} keys %food) {
# Defeference the list, then sort it, join it and print it.
printf("%d -> %s\n",
$happy_factor,
join(", ", sort @{$food{$happy_factor}}));
}
Output ----
10 -> apple
20 -> cake, drinks
30 -> banana
50 -> eggs
--
================================================================
Mike Balenger
MBalenger@att.net migrating toward MichaelRunningWolf@att.net)
(732)809-3613 cell
All mammals learn by playing.
------------------------------
Date: Thu, 02 Nov 2000 05:08:02 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: OT: Yes there _are_ stupid questions. Anyone collect them?
Message-Id: <3A00F9BE.75BAA525@home.com>
Tad McClellan wrote:
>
> On Wed, 01 Nov 2000 23:43:25 GMT, Martien Verbruggen
> <mgjv@tradingpost.com.au> wrote:
>
> >then sends "GET RICK QUICK(LY) !!!!!!"
>
> I'll bet that made Rick feel uneasy...
I'm already on my way out of the country.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Thu, 02 Nov 2000 05:48:01 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: OT: Yes there _are_ stupid questions. Anyone collect them?
Message-Id: <slrn90200h.l2.mgjv@verbruggen.comdyn.com.au>
On Thu, 02 Nov 2000 05:08:02 GMT,
Rick Delaney <rick.delaney@home.com> wrote:
>
> Tad McClellan wrote:
> >
> > On Wed, 01 Nov 2000 23:43:25 GMT, Martien Verbruggen
> > <mgjv@tradingpost.com.au> wrote:
> >
> > >then sends "GET RICK QUICK(LY) !!!!!!"
*grumble*
> >
> > I'll bet that made Rick feel uneasy...
>
> I'm already on my way out of the country.
There's no escape. The great Rick Spam Machine will find you wherever
you are.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Wed, 1 Nov 2000 23:04:06 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl Question
Message-Id: <slrn901ptm.das.tadmc@magna.metronet.com>
On Wed, 01 Nov 2000 19:10:50 GMT, Mark-Jason Dominus <mjd@plover.com> wrote:
>
>In article <ant0117327a1fNdQ@oakseed.demon.co.uk>,
>James Taylor <james@NOSPAM.demon.co.uk> wrote:
[ snip "indicators" that get articles ignored ]
>I also kill off posts that contain 'urgent' because I figure that it's
>probably too late by the time I get to them anyway.
Me too! (I also killfile the whole domain associated with that phrase)
I kill ones that start with "looking for".
Usenet ain't a search engine.
>I also kill off
>posts with subjects that end in '!', because experience has shown that
>they're not ususally worth my while.
I make individualized entries for _habitual_ Jeopardists
for the same reason.
I managed to avoid killing based on the From: header for a few
years, but eventually wore down and now have about 100 of them.
Most are reviewed/removed every few months. Others have an
eternal home in my killfile.
But let's not get too carried away with the negative. There are
things that get positive scores too :-)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 2 Nov 2000 00:07:38 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl Question
Message-Id: <slrn901tkq.das.tadmc@magna.metronet.com>
On Thu, 2 Nov 2000 01:20:00 +0000, James Taylor
<james@NOSPAM.demon.co.uk> wrote:
>In article <slrn9014v6.vf1.mgjv@verbruggen.comdyn.com.au>, Martien Verbruggen
><URL:mailto:mgjv@tradingpost.com.au> wrote:
>>
>> I won't read them, normally. The only reason that I'm reading this is
>> that Tad followed up to the original post.
>It's spooky to think that a choice of subject line could render my
>post invisible to a number of knowledgeable people.
So could your address munging choice. You hit one of my killfile
rules. The only reason I'm reading this is that Martien
followed up to this post, and I saw that, and went looking
for the post he was replying to.
(It may be interesting to note how many of the "regulars" here
have munged their email addresses...
)
>It feels like an
>indiscriminate censorship,
No, it is *discriminate* censorship.
These "indicators" have shown high correlation with "of small value"
in the experience of many, so they kill them to maintain just
enough sanity to enable them to keep coming here at all.
[ During my recent sabbatical from the newsgroup, I was actually
here. I was using the time I usually spend answering questions
"tuning" my killfile.
I _did_ try indiscriminate censorship. I gave -10 to anything
that matched /./ (i.e. every article), then pulled articles
back into visibility based on From and Subject.
It didn't work out too well. Too many babies went with
the bath water.
]
The sad truth is that the newsgroup will never be "like it was"
where you could learn something from nearly all posts. Used to
get my questions here answered by Larry Wall. That doesn't
happen anymore.
The number of posts has risen, while at the same time, the
quality of posts has decreased. The "payback" from reading
Usenet regularly has exceeded the "cost" of reading for
many Very Good Perl Programmers. So they are not here
anymore. A valuable resource no longer available to us.
Perl going "mainstream" is not All Good...
>or one might even go as far as to call it
>unfair discrimination.
Then I'll bet my rule mentioned above seems even more unfair.
(but I "take back" the negative score of /spam/i for some
individuals by giving them a corresponding positive score.
I'm actually still experimenting with that particular rule...
)
When I notice that 19 out of 20 posts with the "foobar"
indicator are of little value, it gets a killfile entry.
I know I'm throwing away 5% good stuff, but the alternative
is to not read the group at all, and give out NO answers).
With a killfile, at least _some_ questions still get answers.
And with any luck, a good post will navigate the (dissimilar)
killfile minefields and make it through to someone qualified
to answer it (or not).
>Although I have to admit I'm secretly tempted
>to discriminate too. ;-)
It seems dutiful to me to resist as long as you can.
I think for most it was a "killfile or abandon the group altogether"
type of choice.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 2 Nov 2000 06:04:58 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Perl Question
Message-Id: <ant02065863dfNdQ@oakseed.demon.co.uk>
In article <slrn901hp5.l2.mgjv@verbruggen.comdyn.com.au>, Martien Verbruggen
<URL:mailto:mgjv@tradingpost.com.au> wrote:
> \begin[more]{offtopic}
>
> slrn
>
> Most newsreaders put a header in the post that identifies them.
> Mine's not an exception :).
Duh! Of course. :-)
> \end{offtopic}
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Thu, 2 Nov 2000 06:12:34 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Perl Question
Message-Id: <ant0206349eefNdQ@oakseed.demon.co.uk>
In article <8tqsi6$cdl$1@provolone.cs.utexas.edu>, Logan Shaw
<URL:mailto:logan@cs.utexas.edu> wrote:
> In article <ant020100339fNdQ@oakseed.demon.co.uk>,
> James Taylor <james@NOSPAM.demon.co.uk> wrote:
> >It's spooky to think that a choice of subject line could render my
> >post invisible to a number of knowledgeable people.
>
> Why? Isn't the Subject line supposed to contain useful information?
> Is that information supposed to be used by people in determining
> whether they want to read the article?
Yes I see what you're saying. The bit I found "spooky" was that
someone might score certain words very negatively, and I might
then unknowingly use them in my subject line. For example, say
you were to score down "money" to avoid make money fast schemes,
"Perl" and "question" to avoid newbies, and say "CGI" too.
Then by chance someone might post a subject of
Questionable ethics of money laundering at Perl/CGI conference
and get completely ignored by everyone leading the poster to
think there must be a conspiracy of silence.
Hope you like the contrived example. :-)
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Thu, 2 Nov 2000 00:53:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl Question
Message-Id: <slrn9020a0.dh0.tadmc@magna.metronet.com>
On Thu, 2 Nov 2000 06:12:34 +0000, James Taylor
<james@NOSPAM.demon.co.uk> wrote:
>In article <8tqsi6$cdl$1@provolone.cs.utexas.edu>, Logan Shaw
><URL:mailto:logan@cs.utexas.edu> wrote:
>> In article <ant020100339fNdQ@oakseed.demon.co.uk>,
>> James Taylor <james@NOSPAM.demon.co.uk> wrote:
[ snip - the Subject is _supposed_ to be used for filtering ]
>Yes I see what you're saying. The bit I found "spooky" was that
>someone might score certain words very negatively, and I might
>then unknowingly use them in my subject line. For example, say
>you were to score down "money" to avoid make money fast schemes,
>"Perl" and "question" to avoid newbies, and say "CGI" too.
>Then by chance someone might post a subject of
>
>Questionable ethics of money laundering at Perl/CGI conference
>
>and get completely ignored by everyone
^^^^^^^^
Naw. The poster would get email spams trying to sell laundry
detergent BELOW WHOLESALE!!
(unless they filter or munge :-)
>leading the poster to
>think there must be a conspiracy of silence.
Oh, I see. You're right. We wouldn't want them catching on to us.
I better be silent...
>Hope you like the contrived example. :-)
It was very nice.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2000 05:36:04 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Perl style and module searches
Message-Id: <837M5.17756$G95.5416466@typhoon.southeast.rr.com>
Dave E <dave_at_hm@hotmail.com> wrote in message
news:3A00BB1E.41FDF922@hotmail.com...
> I have 2 newbie questions:
>
> 1) Is there a style, or "best practices" guide for Perl?
Tom Christiansen's style talk from a conference a couple of years ago covers
this kind of thing. You can find it at
http://www.cpan.org/doc/FMTEYEWTK/style/slide-index.html.
> 2) Is there some searchable index for module capabilities?
search.cpan.org
hth,
p
------------------------------
Date: Thu, 02 Nov 2000 07:08:27 GMT
From: msalerno@my-deja.com
Subject: Re: Quick question - Still new at this !
Message-Id: <8tr3t9$fhv$1@nnrp1.deja.com>
In article <8tnv4c$tke$1@nnrp1.deja.com>,
msalerno@my-deja.com wrote:
> I want to start off thanking all of you who have helped me get this
far.
> And I will post non-jeopardy style from now on !
>
> Hi there, I am working on a script that will process ip addresses.
The
> below is the part where I get the ip addresses. I need to make sure
> that the ip addresses are not the same. In order to do so I need to
> break down the addresses (ex. 127.0.0.1 = 127.000.000.001). So I need
to
> compare each octet as its own number. I am looking for an efficient
way
> to do this. I have gotten this far but now I am stuck. Any help
would
> be appreciated.
>
> Thanks,
> Matt
Hi there again! I have gotten much further now thanks to all of the
feedback and the Llama & Camel books.
I need a statement that will filter out any invalid characters from the
octet. I want to allow only numbers between 1 and 255. I want to throw
an "Bad IP" if [a-zA-Z] and any other characters (like !@#$!%#^%)
are given. I don't know how to add that to the unless statement. Also,
what would be the best way to state that 192.168.12.1. and
192.168.12.1.122 are also invalid ? Any additional tips are always
appreciated.
Thanks,
Matt
#!/usr/bin/perl -w
sub ip_check {
$_[0]=~s/(^|\.)0+(\d)/$1$2/g;
my @ipa = split /\./, $_[0];
my $oct = 0;
for (1..4)
{
unless ($ipa[$oct] < 0 && $ipa[$oct] >= 255)
{
$oct++;
next;
}
print "\nBad Ip\n";
exit;
}
print "\nValid IP\n";
return $_[0];
}
print "Enter the First IP Address: ";
chomp($ip1 = <STDIN>);
print "Enter the Second IP Address: ";
chomp($ip2 = <STDIN>);
($comp1) = ip_check($ip1);
($comp2) = ip_check($ip2);
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 02 Nov 2000 05:46:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regular expression
Message-Id: <upv10tgbbgudhq2b5codkfvb0415ajcfvf@4ax.com>
Tad McClellan wrote:
>Doubling backslashes in single quoted strings is useless,
>so why do it?
I wouldn't dare to call it useless.
$_ = 'string\with\a\backslash\'oops!';
You don't always need backslashes in qingle quotish strings, that's
true. But simply forgetting about it is dangerous. You'd end up thinking
that '\\' is two backslahes.
Therefore, I always double all backslashes.
--
Bart.
------------------------------
Date: Thu, 02 Nov 2000 05:27:53 GMT
From: "Michael Balenger" <MBalenger@worldnet.att.net>
Subject: Re: Spaces to tab
Message-Id: <tX6M5.17348$xJ4.820926@bgtnsc06-news.ops.worldnet.att.net>
> I mis-stated my question; thank you all for replying, however. My
> intent was actually to convert every four spaces of whitespace at the
> beginning of the line such that 10 spaces=2 tab (two extra spaces
> eliminated), 7 spaces=1 tab, and any extraneous whitespace after the
> code portion of the line (save the newline character) be converted to
> null.
Ambiguious requirements:
1) "two extra spaces eliminated
2) "any extraneous whitespace ... converted to null"
It's a nit; pick which one fits.
I've coded #1, and commented #2.
Thanks to Damian Conway for suggesting Text::Tabs.
#! /bin/perl -w
use Text::Tabs;
$tabstop = 4;
while ( <DATA> ) {
s/^(\s+)/unexpand($1)/e; # Turn leading whitespace to spaces.
s/^(\t*)[ ]*/$1/; # Remove space after leading tabs.
# s/^(\t*)\s*/$1/; # Remove whitespace after leading tabs.
print;
}
__DATA__
0
1
2
3
4
5
6
7
8
9
10
11
12
Output - sorry if tabs got corrupted on the way to you.
0
1
2
3
4
5
6
7
8
9
10
11
12
0
1
2
3
4
5
6
7
8
9
10
11
12
--
================================================================
Mike Balenger
MBalenger@att.net migrating toward MichaelRunningWolf@att.net)
(732)809-3613 cell
All mammals learn by playing.
------------------------------
Date: Thu, 02 Nov 2000 05:33:14 GMT
From: "Michael Balenger" <MBalenger@worldnet.att.net>
Subject: Re: Spaces to tab
Message-Id: <u07M5.17353$xJ4.822585@bgtnsc06-news.ops.worldnet.att.net>
> Output - sorry if tabs got corrupted on the way to you.
Obviously, I double-pasted the output. Sorry.
------------------------------
Date: Wed, 1 Nov 2000 23:23:40 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Stultiloquent Queries (was: even or odd?)
Message-Id: <slrn901r2c.das.tadmc@magna.metronet.com>
On 01 Nov 2000 19:05:23 -0800, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "David" == David Steuber <nospam@david-steuber.com> writes:
>
>David> You mean this question had been asked before? How many VB programmers
>David> are there?
>
>And would it be an even or odd number of VB programmers?
An even number of odd VB programmers?
Would it be odd if it was even?
Or even if it was odd?
( I'm suddenly feeling Suessish )
How can I hide my VB programmers?
How can I write a counter to count my VB programmers?
Make it stooooopppp! (me, that is. stopping "the questions" is futile)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Nov 2000 06:02:10 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Using 'format' and 'write' multiple times?
Message-Id: <8tr012$1b5a$3@news.enteract.com>
Mark-Jason Dominus <mjd@plover.com> wrote:
> The reason Gwyn is asking for the real code is that it often happens
> that someone will come in here, show some faked-up code that they
> *think* captures the essence of the problem, when in reality the
> problem is something else entirely, and they have suppressed
> all the information that would have let us figure out what it was.
It is also quite often the case that people come here and give what they
think is an adequate description of a problem when in reality they've
forgotten that we can't take for granted all the little details that they
can. In the extreme, it's analogous to a patient calling a doctor and
saying "I don't feel good. What's wrong with me?" The patient knows the
details of what feels wrong, but he hasn't communicated them to the doctor
(I should note that in real life, physicians with patients who are either
very young children or elderly people with some form of dementia have to
deal with *exactly* that scenario; it's plain that the patient feels bad,
but is not capable of describing how). There's not much you can do in
such a situation other than ask for more details. Trying to guess at them
will usually lead you down the wrong track.
------------------------------
Date: Wed, 1 Nov 2000 23:07:27 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <slrn901q3v.das.tadmc@magna.metronet.com>
On Wed, 01 Nov 2000 19:59:38 -0800, Mark Thompson
<mark-lists@webstylists.com> wrote:
>On Thu, 02 Nov 2000 00:02:25 GMT, jerome@activeindexing.com (Jerome
>O'Neil) wrote:
>
>>Mark Thompson <mark-lists@webstylists.com> elucidates:
>I have the idea that there's an entire
>online collection of documentation that I'm missing if I could ever
>find it.
Ah hah!
My PSI::ESP module works like a well-oiled machine!
:-)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 01 Nov 2000 22:11:45 -0800
From: Mark Thompson <mark-lists@webstylists.com>
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <f2120tgagnerg93inu7qt55ndtt3qfkdgk@4ax.com>
On Wed, 1 Nov 2000 21:52:17 -0500, tadmc@metronet.com (Tad McClellan)
wrote:
>On Thu, 02 Nov 2000 00:02:25 GMT, Jerome O'Neil
> <jerome@activeindexing.com> wrote:
>>Mark Thompson <mark-lists@webstylists.com> elucidates:
>>> On Wed, 01 Nov 2000 21:53:57 GMT, jerome@activeindexing.com (Jerome
>>> O'Neil) wrote:
>>>
>>>>Its a fine way of doing things. Just ensure you use File::Find when
>>>>you do it.
>>>
>>> Well, had my plans of how I was going to do this until I saw you
>>> mention File::Find and I really can't find much on it that would help
>>> me use it (I found some cryptic documentation but even the Perl 5
>>> books that I have don't cover this to any level but they cover the old
>>> methods extensively.)
>>
>>Well, lets take another tac on this, then. What in particular do
>>you find 'cryptic' about the documentation for File::Find? I find it
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>pretty well documented, myself, and am always curious as to what parts
>>others find problematic.
>>
>>I think once we know that, you'll be much enlightened.
>
>
>I might guess that perhaps Mark does not know how to get the
>real (official) documentation.
>
>So, just in case that is it, you access the File::Find docs like this:
>
> perldoc File::Find
>
>Is _that_ the "cryptic documentation" that you are referring to?
Exactly, it's not that it's cryptic in what's actually there, but it's
cryptic in that it's showing there should be a lot more to the
documentation than is showing there (it gives references to things
that aren't documented there.)
One thing I am noticing is that even though pretty much anything can
be done with modules, I don't see as many code examples doing thing
with them.
------------------------------
Date: 1 Nov 2000 23:18:37 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <3a01073d$1@cs.colorado.edu>
In article <slrn901ln1.ctb.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
>I might guess that perhaps Mark does not know how to get the
>real (official) documentation.
>
>So, just in case that is it, you access the File::Find docs like this:
>
> perldoc File::Find
No. That's wrong--you are not portable. You merely look in the
file that contains the module. At the end (typically) is its
documentation.
Time to post perlrtfm again.
--tom
------------------------------
Date: 1 Nov 2000 23:19:44 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <3a010780$1@cs.colorado.edu>
In article <p9p10tk2sp6s2q8poklv74onp8afh910vh@4ax.com>,
Mark Thompson <mark-lists@webstylists.com> wrote:
>I have the idea that there's an entire
>online collection of documentation that I'm missing if I could ever
>find it.
Read
The
Fabulous
Module
--tom
------------------------------
Date: Thu, 02 Nov 2000 05:51:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: What about CGI.pm?
Message-Id: <05020t8is7vugq78mpd9o1uij3l3bemsu1@4ax.com>
Alan J. Flavell wrote:
>So, why is this a problem? If you have a server which is busy running
>CGI.pm, then surely CGI.pm will be in the disk cache?
Only that it eats up disk cache space. Process a large data file, and
the contents of CGI.pm will have been dropped.
--
Bart.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4790
**************************************