[17378] in Perl-Users-Digest
Perl-Users Digest, Issue: 4800 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 21:10:26 2000
Date: Thu, 2 Nov 2000 18:10: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: <973217412-v9-i4800@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 2 Nov 2000 Volume: 9 Number: 4800
Today's topics:
Re: Perl Question (Martien Verbruggen)
Re: Perl Question (Martien Verbruggen)
Re: Perl Question <james@NOSPAM.demon.co.uk>
Re: Perl style and module searches <dave_at_hm@hotmail.com>
Re: Perl style and module searches (Tom Christiansen)
Re: Question about "use strict;" <ren.maddox@tivoli.com>
Re: regexp-question (probably simple?) <ianb@ot.com.au>
Removing carriage returns from cgi <gods-apollo@home.com>
Re: String manipulation?? <tim@ipac.caltech.edu>
system command question <ylwang@u.washington.edu>
timeout with Net::DNS <mackiew@seciu.edu.uy>
Tk :: logo on top and terminal on background <diab.lito@usa.net>
Re: Want to process all files less than 24 hours old (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 03 Nov 2000 00:54:27 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Perl Question
Message-Id: <slrn904363.l2.mgjv@verbruggen.comdyn.com.au>
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:
> > >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?
[snip]
> 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. :-)
It's spot on. If you had also spelled Perl as PERL, it would get
enough negative points to end up killed according to my scorefile.
It's the price I have to pay for generalising subjects I've seen in
the past that have a high correlation to content that I'm not
interested in.
I'd rather not have a scorefile. But I need to. Some of the scores are
simple measures to maintain a low blood pressure, others are there to
save me time. It's not perfect, but I enjoy it more than not reading
the group at all.
Martien
--
Martien Verbruggen |
Interactive Media Division | Think of the average person. Half of
Commercial Dynamics Pty. Ltd. | the people out there are dumber.
NSW, Australia |
------------------------------
Date: Fri, 03 Nov 2000 01:08:24 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Perl Question
Message-Id: <slrn904408.l2.mgjv@verbruggen.comdyn.com.au>
On Thu, 2 Nov 2000 20:33:19 +0000,
James Taylor <james@NOSPAM.demon.co.uk> wrote:
> In article <m3bsvy4avo.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox
> <URL:mailto:ren.maddox@tivoli.com> wrote:
> >
> > My newsreader, gnus, has two commands that I use for this. One pulls
> > up the parent article of the current article and the other pulls up
> > all articles in the current thread. Obviously, in both cases the
> > articles must still be available to be displayed.
So does slrn. Although the second one does require your news server to
support the XPAT extension.
> Hmmm, I think you misunderstood my question which was to do with what
> algorithm a program I want to write would use to track a thread backwards.
Tracking a thread backwards is easy enough. You get the References:
header from the article, and request each article mentioned in there
from the news server. That way you also get the article number on that
news server, and you can adapt your .newsrc or whichever file you use
to record read messages. You can use Net::NNTP or News::NNTPClient to
do the communication with the server.
To reconstruct a full thread, when you only have one article in the
thread, can be done by first finding the top most article (that
started the thread), and then using XPAT to find all articles that
have this article's ID in the References heading.
Whether you can do this from within your client is another thing. But,
you could write an external Perl program, that given a article number
and newsgroup could do both of the above, and use the information
gained fromt he server to update your newsrc file. On next reading the
group, you should see those articles again. How interactive this all
gets depends on your newsreader.
Of course, you could also just write a smallish perl client whose only
task would be to get a full thread from the server and display it to
you. It shouldn't even need to be very complex. It could just get the
articles, display them in some order, and on selection get the body
(maybe strip some headers) and pipe it through less for you to read.
This is exactly one of those things that could be hacked up quite well
in Perl with not too much effort.
> Sorry, perhaps I shouldn't be high-jacking this thread to ask programming
> questions, especially when so many people have scored this thread down
> based on the original poster's poor choice of subject line. Oh well... :-)
Hey, programming is what this group is about :) I stuck a few module
names in the above to make sure there was some perl relevance, and
presto :)
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Fri, 3 Nov 2000 02:01:18 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Perl Question
Message-Id: <ant030218b07fNdQ@oakseed.demon.co.uk>
In article <slrn904408.l2.mgjv@verbruggen.comdyn.com.au>, Martien Verbruggen
<URL:mailto:mgjv@tradingpost.com.au> wrote:
>
> Tracking a thread backwards is easy enough.
[snip useful info]
Yes, I think so too, especially as I have a month's worth of articles
in my local spool directory, and an index of article numbers and
references already available which is maintained by the news fetcher.
> Whether you can do this from within your client is another thing.
My newsreader is pretty dumb but all I should need to do is close it,
run the said script to update my .newsrc and reopen the newsreader.
> Of course, you could also just write a smallish perl client whose only
> task would be to get a full thread from the server and display it to
> you. It shouldn't even need to be very complex. It could just get the
> articles, display them in some order, and on selection get the body
> (maybe strip some headers) and pipe it through less for you to read.
Well that was my initial thought, but I like the idea of modifing the
.newsrc because I can then reply/forward/file/etc articles which reading
them in my normal familiar newsreader. I find it amusing that despite
the fact that my platform would seem totally alien to a UNIX user, by
translating RISC OS concepts into UNIX ones on the fly I am able to
hold a meaningful discussion about these things. If only you knew...
> This is exactly one of those things that could be hacked up quite
> well in Perl with not too much effort.
Yes, I haven't been using Perl for long, but it has given me so much
freedom that it's hard to convey the sheer joy of it. I'm sure you all
understand that already though. :-)
Thanks for your help, everyone.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Thu, 02 Nov 2000 17:14:59 -0800
From: Dave E <dave_at_hm@hotmail.com>
Subject: Re: Perl style and module searches
Message-Id: <3A021193.6761027B@hotmail.com>
...just to say "Thank You"
thanks to Jon Ericson, Gwyn Judd, and others for suggesting:
http://www.stonehenge.com/merlyn/
http://search.cpan.org/
Both are very much what I'm looking for.
Tom Christiansen's style talk
(http://www.cpan.org/doc/FMTEYEWTK/style/slide-index.html.),
suggested by Philip Garrett, looks very interesting though I've not spent
much time with it yet.
http://perldoc.cpan.org, recommended by Elaine Ashton, seems to give me more
useful search results than http://search.cpan.org. At least on first
test. Perldoc.com also looks quite interesting.
Tom Christiansen suggested:
"Have you tried grepping the modules that you already have?
Why not? Do you know where you modules are? Do you know
how to look at a file?"
Well, the thought occurred to me when I was trying to get Perldoc to search
through the pod text rather than the module names, but I figured there must
be an easier way. And there is :) -- perldoc.cpan.org has a search engine
for this.
Anyway, thanks to all for the above information (and more).
as for the "newbie" thing, you'll note it was not in the subject line :)
Though, I should have known better to add that in. I do customer support
and know what it's like when questions are prefaced by "I'm computer
illiterate..." like it was some badge of honour. My intent was to say "I'm
only looking for basic information."
David...
------------------------------
Date: 2 Nov 2000 18:28:26 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Perl style and module searches
Message-Id: <3a0214ba$1@cs.colorado.edu>
In article <3A021193.6761027B@hotmail.com>,
Dave E <dave_at_hm@hotmail.com> wrote:
>Well, the thought occurred to me when I was trying to get Perldoc to search
>through the pod text rather than the module names, but I figured there must
>be an easier way. And there is :)
That's right. There is. You install my rewritten version. :-)
--tom
------------------------------
Date: 02 Nov 2000 16:16:31 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Question about "use strict;"
Message-Id: <m3em0u10lc.fsf@dhcp11-177.support.tivoli.com>
zabor@my-deja.com writes:
> When I "use strict;" I understand how to use the "my()" way of defining
> the variables. But do not understand how to define a global variable. I
> have seen the example "$X::foo = 1;", can I use
> this "$X::foo,foo2,foo3", how do I define multiple global variables?
Perl doesn't really have global variables, it has package variables.
In "$X::foo = 1", "X" is the package and "foo" is the variable.
"$X::foo" is a fully qualified package variable.
If you want to access package variables from the current package
without having to fully qualify them, you can declare them with "use
vars":
use vars qw/$foo $foo2 $foo3/;
Or, as of Perl 5.6, you can use "our", which is syntactically the same
as "my", but gives access to the package variable instead of creating
a lexical variable.
our($foo, $foo2, $foo3);
Please reference:
perldoc -f package
perldoc vars
perldoc -f our
perldoc -f my
perldoc perlsub
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 03 Nov 2000 09:25:11 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: regexp-question (probably simple?)
Message-Id: <3A01E9C6.77343121@ot.com.au>
Felix Drüke wrote:
> What would be the best method to NOT match something without
> saying "if !/bla/" ?
If you really must (for example, you can't change the code, but you can
pass in a different regex), you can do something like the final example:
#!/usr/bin/perl -w
use strict;
use vars qw(@list);
@list = ("line1 xline1","line2 xline2","line3 xline3");
print "--- print \$_ if xline1 not matched\n";
for (@list) { print "$_\n" if !/xline1/ }
print "--- print \$_ if ^line2 not matched (?)\n";
for (@list) { print "$_\n" if /^(?!line2)/ }
print "--- print \$_ if xline3 not matched (?why does it not
work?)\n";
for (@list) { print "$_\n" if /(?!xline3)/ }
print "--- print \$_ if xline3 not matched\n";
for (@list) { print "$_\n" if /^(?:.(?!xline3))*$/ }
__END__
Giving:
--- print $_ if xline1 not matched
line2 xline2
line3 xline3
--- print $_ if ^line2 not matched (?)
line1 xline1
line3 xline3
--- print $_ if xline3 not matched (?why does it not
work?)
line1 xline1
line2 xline2
line3 xline3
--- print $_ if xline3 not matched
line1 xline1
line2 xline2
The !// is clearer, however, and I would expect it to be faster. I
haven't benchmarked it, so I'm only guessing. I don't expect there would
be a really huge difference, however, because in each case the regex
engine would be trying to match xline3 at each character in the string,
and stepping to the next if it failed, returning when it either matched
or hit the end of the string. To benchmark it, you'd need to try long
and short strings that both match and fail, to get a true feel for it.
(Or you'd need to understand the regex engine guts.)
Regards,
Ian
------------------------------
Date: Fri, 03 Nov 2000 01:17:57 GMT
From: "John" <gods-apollo@home.com>
Subject: Removing carriage returns from cgi
Message-Id: <9noM5.45612$E85.1153991@news1.sttls1.wa.home.com>
I have an input form with several <textareas>.
Here is the code I pull it down with.
unless (@mailingaddress = $query->param('mailingaddress'))
{
print_empty("Mailing Address");
}
for ($i=0; $i < @mailingaddress; $i++)
{
$mailingaddres[$i] =~ s/\\/\/g;
chomp($mailingaddress[$i]);
}
When I go to write mailingaddress to a file.. I get those damned ^M all over
the place.
I can't seem to take those out.. I though chomp would have done it. I used
=~ s/\n/<BR>/g .. when I use =~ s/\n//g ... that doesn't seem to do a damn
thing.
Anyone know how to take the ^M out from the input into an array?
John
------------------------------
Date: Thu, 02 Nov 2000 16:29:16 -0800
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: String manipulation??
Message-Id: <3A0206DC.15CE4368@ipac.caltech.edu>
Murx Cedarstorm wrote:
>
> I made a subroutine.pl library in where i read data from a file into an
> array. the name of this array is passed on to the subroutine like this:
>
> the subroutine in subroutines.pl:
>
> open(readFile, $_[0]) || die;
> $_[1] = <readFile>;
> close(readFile);
>
> and it's called like this:
>
> &_read("template.dat",@template);
>
> but somehow it does not work...yes i set the "require = subroutines.pl"
> stuff, other subs do work...the problem is in the name of the array,
> @template...
You need to read the perlref doc. When you do, you'll understand this:
use strict;
use warnings;
... v
&_read("template.dat",\@template);
...
sub _read {
open(FILE, $_[0]) || die "Open of $_[0] failed; $!;
@{$_[1]} = <FILE>;
close(FILE);
return $_[1]; # For sugar, make the array ref a return value too.
}
Note some additions beyond what you asked for which you may have occasion to
eventuall appreciate. You can Read about Them in the Fabulous Manual(s).
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Thu, 2 Nov 2000 15:59:31 -0800
From: "Y. Wang" <ylwang@u.washington.edu>
Subject: system command question
Message-Id: <Pine.A41.4.21.0011021551260.112638-100000@dante20.u.washington.edu>
Hi,
I have a part of code as follows
....
$cmd="para parafile < $tmpinput > /dev/null";
system("$cmd")==0 or die "Failed to do: $cmd\n";
....
para program asks for parameter from tmpinput and write out in
parafile. Since there are some interative information, e.g. Input N:
I let those information go to /dev/null.
When I use the same code, it runs well in "version 5.005_02 built for
i86pc-solaris". But I got errors any time when I ran it on Red Hat
6.2. I tried two different RPMs in it, neither perl-5.00503-10.i386 nor
perl-5.00503-12.i386 works. The error was due to nonzero was returned
from system command.
Can someone tell me how to solve this problem?
Thanks,
Yalin
------------------------------
Date: Thu, 2 Nov 2000 21:44:50 -0300
From: "andres mackiewicz" <mackiew@seciu.edu.uy>
Subject: timeout with Net::DNS
Message-Id: <8tscdf$tdm$1@vaimaca.rau.edu.uy>
Hi everyone.
I am using Perl and the module Net::DNS for performing a zone transfer.
My problem is that I create a resolver object that seems to ignore the
"timeout" parameter I set.
I put the code here:
-----------------------
#!/usr/bin/perl -w
use Net::DNS ;
my $res = new Net::DNS::Resolver;
$res->nameservers("UUCP-GW-2.PA.DEC.COM");
$res->tcp_timeout (1) ;
$res->retry (1) ;
$res->retrans (1) ;
print "before transfer" ;
print "timeout: ", $res->tcp_timeout, "\n" ;
print " retrys: ", $res->retry, "\n";
print " retrans: ", $res->retrans, "\n";
my @records = $res->axfr("uy.");
foreach (@records) {
$_->print ;
}
print "after transfer " ;
-----------------
The programs works well when the nameserver works well, but the nameserver
"UUCP-GW-2.PA.DEC.COM" sometimes works but sometimes delays a long time.
I want the resolver to wait no more than 1 second, retry 1 time and wait 1
second before retrys..
The "prints" do print the right values (1, 1, 1), but after printing
"retrans" the program delays for some minutes...
Thank you..
------------------------------
Date: Fri, 03 Nov 2000 01:35:35 GMT
From: Mario <diab.lito@usa.net>
Subject: Tk :: logo on top and terminal on background
Message-Id: <8tt4p7$7jq$1@nnrp1.deja.com>
I just installed Tk for Perl and I see 2 problems:
1.There is a small red 'tk' icon at the top left corner of the window.
2.I have the terminal on the background.What is it supposed to be there
for??
Is it possible to avoid these 2 things?
Thanks a lot.
Mario
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 2 Nov 2000 19:08:13 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <slrn9040fd.gjr.tadmc@magna.metronet.com>
[ Please don't quote entire articles like that. Quote only enough
to establish the context for your comments.
Each Usenet post is saved to *tens of thousands* of computers
around the world.
Nothing to gain from spending resources just because they
aren't your resources.
Thanks.
]
On Thu, 02 Nov 2000 14:34:15 -0800, Mark Thompson
<mark-lists@webstylists.com> wrote:
>On Thu, 2 Nov 2000 15:36:08 -0500, tadmc@metronet.com (Tad McClellan)
>wrote:
[ snip 60 lines ]
>>Third time's the charm? ...
>
>Sorry, I changed the real company name's directory with "companyname"
>and must've lopped off the end quote. Only two lines changed are the
>lines with the filenames.
You shouldn't do that.
It will get you ignored.
Make the changes in your real program, and make sure that
your real program still runs, _then_ import the code into
your newsreader.
>I do have a question that maybe you or someone else can answer, does
>use strict or -w slow things down any?
There is a Benchmark.pm module for answering such questions.
Machines doing the work instead of humans again. You're not
Lazy enough yet :-)
If the tiny slowdown is something that concerns you, then
you are probably using the wrong language. C and assy are for when
speed is critical.
Perl is for when (minimizing) human labor is critical :-)
Machines are cheap. People are expensive.
>Once I've tested the program
>(as I've done), should I remove them knowing that I can put them back
>if I need to make changes to the program?
No.
Some of the output they make is triggered by the _data_.
So you could take them out, knowing that you could put them
back in if you need to process different data.
(I hope you see how ridiculous that suggestion is :-)
I have heard arguments that you should remove -w for production,
but I do not agree with them, and so won't be repeating them here.
I have never heard a reasonable argument for leaving "use strict" out.
>#!/usr/local/bin/perl5 -w
>
>use strict;
>use File::Find;
>
>my $logfiledir = '/u/logs/companyname';
>my $databasefile = '/u/companyname/data/download_req.txt';
>
>my %log;
>my %data;
Heh! I'm seven lines into the code and I can't find an excuse
for stopping. Guess I'll have to press on then... :-)
>sub readdatabasefile
>{
You should avoid global variables whenever possible.
They are easily avoided here.
Pass $databasefile as a subroutine argument instead of
communicating with the subroutine via global variables.
perldoc perlsub
describes how to pass and access subroutine arguments.
> open(DBFILE, $databasefile);
You should always, yes *always*, check the return value from open():
open(DBFILE, $databasefile) || die "could not open '$databasefile' $!";
Be sure to include the $! special variable in your diagnostic message.
perldoc perlvar
to find out about $!.
> while(<DBFILE>)
> {
> my $dataitem;
> my $rest;
>
> chomp;
> ($dataitem, $rest) = split(/\t/, $_, 2);
If you like, you can combine the declaration with the initialization:
my($dataitem, $rest) = split(/\t/, $_, 2);
and do away with the 2 my() lines above.
> $data{$dataitem} = $_;
>
> }
> close (DBFILE);
Explicit close() is a Very Good Idea!
>}
>
>
>sub wanted
>{
> if (-f && (-C ($_) < 1) && /\.d$/)
> {
>
> open(LOGFILE, $File::Find::name);
Check the return value.
Just because you _asked_ for the file to be opened doesn't mean
it actually got opened.
Sometimes you don't get what you ask for.
> while(<LOGFILE>)
> {
> my @logitem;
> my $time;
> my $cookie;
> my $file;
> my @cookies;
> my $count;
>
> chomp;
> @logitem = split(/\t/, $_, 4);
> $time = $logitem[0];
> $cookie = $logitem[1];
> $file = $logitem[2];
You can combine several lines above, and eliminate the @logitem
temporary variable if you like:
# get the first 3 tab-sep fields, discard the rest if any
my($time, $cookie, $file) = split(/\t/, $_, 4);
> $cookies[$count - 1] =~ /ManualDownloadCode=(.+)/;
> if ($1)
Yikes!
Another biggie!
Do you realize where the value of $1 comes from if that
pattern match should happen to fail?
If your match fails, $1 will have been set from a *different match*
many of lines above this point in the program.
The "dollar digit" variables are updated only on a *successful*
pattern match.
So you should NEVER use the dollar-digit variables without first
testing to see that the match succeeded.
You can incorporate that easily here though. Instead of "if ($1)":
if ( $cookies[$count - 1] =~ /ManualDownloadCode=(.+)/ ) {
$log{$1}{$file} = 1;
}
> {
> my $manualcode;
> $manualcode = $1;
> $log{$manualcode}{$file} = 1;
> }
You don't need to copy them all around in temp vars like that.
You already have a variable ($1) just use it, as I show above.
>sub outputreport()
>{
> my $user;
> foreach $user ( keys %log )
You can stick the my() right in the foreach if you like:
foreach my $user ( keys %log )
> @dataarray = split("\t",$data{$user});
^^^^
That is misleading. It looks like a string, but it is a pattern match.
Better if pattern matches _look like_ pattern matches :-)
@dataarray = split(/\t/ ,$data{$user});
Overall not too bad.
So you have 3 "big problems" and a bunch of stylistic nitpiks.
1) avoid global variables
2) check open() return value
3) test for successful match before relying on the values in $1, $2...
Hope this helps!
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
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 4800
**************************************