[12202] in Perl-Users-Digest
Perl-Users Digest, Issue: 5802 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 11:07:32 1999
Date: Thu, 27 May 99 08:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 27 May 1999 Volume: 8 Number: 5802
Today's topics:
array of hashes, removing items (Charles R. Thompson)
Re: CGI::Announce (Randal L. Schwartz)
Re: DBM File will not open after Redhat 6.0 upgrade (Dan Wilga)
display status of sevices under NT (Carsten Dieter Wolf)
Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe finsol@ts.co.nz
Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe <jeromeo@atrieva.com>
Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe <jeromeo@atrieva.com>
Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Pe <upsetter@ziplink.net>
Re: File I/O Help Needed (Jason McNorton)
Re: flock and string search. <tchrist@mox.perl.com>
Re: How to write htaccess? <tchrist@mox.perl.com>
Making Perl Wait sherifhanna@my-deja.com
Re: Making Perl Wait (Brad Knowles)
Re: Making Perl Wait <tchrist@mox.perl.com>
Re: Making Perl Wait (Greg Bacon)
My first working script; comments, hints? (Remco Gerlich)
Perl call to c/c++ DLL sbeaulieu@my-deja.com
Re: perl script as an executable <tchrist@mox.perl.com>
Re: please test my new site.. <vincent_vanbiervliet@be.ibm.com>
Re: please test my new site.. <perin@panix7.panix.com>
popgrep (was: please test my new site..) <tchrist@mox.perl.com>
Re: Reading text file <cbarnett@idirect.com>
Re: Reading text file <tchrist@mox.perl.com>
Re: Reading text file <tchrist@mox.perl.com>
Re: Safe.pm necessary for secure CGI? <srosenthal@northernlight.com>
thread vs process izzac@my-deja.com
Re: undef of namespaces <anno4000@lublin.zrz.tu-berlin.de>
Re: using zipcodes to graphically desplay survey result (Randal L. Schwartz)
Re: why doesn't my first program work?? (ok , third or <tchrist@mox.perl.com>
Re: workarounds for prototypes <tchrist@mox.perl.com>
Re: writing binary stuff back to a browser, funky forma (Marko R. Riedel)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 May 1999 13:59:07 GMT
From: design@raincloud-studios.com (Charles R. Thompson)
Subject: array of hashes, removing items
Message-Id: <MPG.11b71b10909809a19896d2@news>
I've been dealing with Chapter 4 in Programming Perl for a few weeks now.
In reading FAQ 4, it is stated I shouldn't remove keys from a hash while
iterating over it. Does this include an array of hashes in a hash?
This is a test hash I am using that would represent 'rows' of a database.
I would like to remove the hashes for records with 'three', 'five' and
'seven' in num. The following example is me just trying to remove the
hash containing 'five' from the array.
I was trying splice for some odd reason last night, but I can't seem to
feed it the items value as an array. I'm kinda stumped.
Any clues, or is this impossible?
CT
#!/usr/bin/perl5 -w
use strict;
use diagnostics;
print "Content-type: text/html\n\n";
my %HSH = (
thing => 'a pseudo db structure',
items => [ {num=>'one'},
{num=>'two'},
{num=>'three'},
{num=>'four'},
{num=>'five'},
{num=>'six'},
{num=>'seven'},
{num=>'eight'},
{num=>'nine'},
{num=>'ten'}, ],
);
my $item = '';
# print all the 'rows'
foreach $item(@{$HSH{items}}){
print "$item->{num}<br>";
}
print "<br>";
# remove one item while running through rows
foreach $item(@{$HSH{items}}){
if ($item->{num} eq 'five'){
splice(@{$HSH{items}}, $item);
}
}
# print out the result, five should be gone
foreach $item(@{$HSH{items}}){
print "$item->{num}<br>";
}
print "complete";
------------------------------
Date: 27 May 1999 07:44:53 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: CGI::Announce
Message-Id: <m1iu9elggq.fsf@halfdome.holdit.com>
>>>>> "Dan" == Dan Kubilos <dkubilo@oxnardsd.org> writes:
Dan> URL listed is
Dan> http://olympia2.adhost.com/~maurice/
Dan> But the maintainer no longer has CGI::Announce available there.
And people wonder why I reject nearly all CLPA announcements that
don't mention CPAN.
<sigh> :)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Thu, 27 May 1999 09:22:00 -0400
From: dwilgaREMOVE@mtholyoke.edu (Dan Wilga)
Subject: Re: DBM File will not open after Redhat 6.0 upgrade
Message-Id: <dwilgaREMOVE-2705990922000001@wilga.mtholyoke.edu>
I> RedHat 6.0 uses the Berkeley DB 2.x libraries instead of the Berkeley DB 1.x
> libraries used in RedHat 5.2 or older. They are not inter-operable.
> That is probably your problem.
>
That would be my guess too. When I updated from 1.x to 2.x, I had to write
a conversion utility to save the DBs in a version-independent format (see
Data::Dumper or Storable) and then import them into the new format.
Berkeley DB 1.x is notorious for destroying my databases, so upgrading to
the latest 2.x is something I would consider essential.
Dan Wilga dwilgaREMOVE@mtholyoke.edu
** Remove the REMOVE in my address address to reply reply **
------------------------------
Date: 27 May 1999 15:31:16 +0100
From: csaa4635@dm.uibk.ac.at (Carsten Dieter Wolf)
Subject: display status of sevices under NT
Message-Id: <374d4924.0@sia.uibk.ac.at>
greetings ...
i am looking for a tool or library (in perl language) to display and watch
the actual status of any running service under win-NT.
in the particular reason i want to stop a service wait till its process
is finished and the restart it again
can anyone help me ? who knows some hinds for me
thanks carsten
------------------------------
Date: Thu, 27 May 1999 14:36:01 GMT
From: finsol@ts.co.nz
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <7ijl8h$nkn$1@nnrp1.deja.com>
In article <374d4028@cs.colorado.edu>,
tchrist@mox.perl.com (Tom Christiansen) wrote:
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc, finsol@ts.co.nz writes:
> :The fact is that CGI shares the same Y2K
> :booby-trap problem as Perl.
>
> It's clever statements like this one that obliterate any shred of
> credibility you pretend to have. There is no programming language
called
> "CGI". You're making this all up, and you look ridiculous. Have you
> ever bothered to read the *real* CGI spec? You should. This is even
> worse than guessing what localtime() does without reading its spec.
> Now you posit a complete language that isn't even there.
>
> Now, go away, kid, and learn something before you embarrass yourself
> again. Lately you can't even open your mouth but to change feet.
>
> --tom
Tom, thought you may be interested to know that I'm not the only
mis-guided soul using the term "programming language" to describe CGI
for expedience.
Check out these two URL's.
http://www.net-ads.com/development/CGI.html
Using CGI & Perl
CGI, or Common Gateway Interface, is a programming language that allows
webmaster to add various interactive features to their websites,
including search engines, free-4-all links pages, clocks, counters,
bulletin boards and more. Using CGI, it is also possible for webmasters
to manage their own advertising inventory by rotating and tracking
banner adviews ...
http://www.itknowledge.com/reference/dir.programminglanguages.perlandcgi
.html
Programming Languages: Perl & CGI
CGI Developers Guide
This book is one of the first books to provide comprehensive information
on developing with CGI (Common Gateway Interface). It covers many of the
aspects of CGI including, interactivity, performance, portability, and
security. After reading this book, the reader will be able to write
robust, secure, and efficient CGI programs.
CGI Manual of Style
CGI is the programming language that allows for accountability on the
Web. This book will help programmers learn the fundamentals behind CGI -
showing how to program the included samples, what to watch out for, and
how to achieve effective scripting. Progressing from easy samples to
more advanced, this book provides users with the skills they need to
provide accountability on their Web site.
Special Edition Using Perl 5 for Web
Programming
With a review by Tom Christiansen ...
Hey, you're famous - this page references your very own self! Perhaps
you need to re-educate these poor folks as well. I'm sure the world will
be a better place once you have eradicated this most serious of
transgressions.
You efforts to educate me in the correct means of using news groups and
the terminology that should be used is, I'm sure, of a greater
importance to the computing world than Y2K awareness.
BTW, while you're checking out URL's, how does the Perl code at these
sites look to you? It doesn't look kosher to me but then I don't claim
to be a Perl expert.
www.hollycole.com/WWWboard/wwwboard.html
# get information
local($string) = @_;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
# calculate useful values
$cent = ($year < 70) ? 20 : 19;
$lyear = $year + $cent*100;
http://www2s.biglobe.ne.jp/~j_okada/free_cgi/j_diary/regist.txt
if ($year > 97) { $year = "19$year"; }
else { $year = "20$year"; }
if (!open (DB, "$data_dir/$year$mon\.dat")) {
http://www.linguistic-funland.com/scripts/RemindMe/remindmecgi.txt
if($data{'Year'} eq "Not Selected"){
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
if($year !~ /0/){
$form_year = "19$year";
}
else{$year = "20$year";}
}
else {
$form_year = $data{'Year'};
Jocelyn Amon
--
Financial Solutions Limited
http://www.ts.co.nz/~finsol/
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Thu, 27 May 1999 07:40:45 -0700
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <374D596D.D9E9F4E3@atrieva.com>
finsol@ts.co.nz wrote:
> Many Perl
> programmers think the mis-use of localtime is a non-issue
> because, based on their limited experience, it does not occur or, if it
> does, it cannot cause any problem worthy of consideration.
We don't think it's a non-issue. We just don't think it's a perl
issue. It's a programmer issue.
> If I saw localtime used in a program to format and output the value
> YYMMDD, I would be unlikely to check the manual just to be sure that YY
> was 'years since 1900' and not the last two digits of the year. I would
> probably only see a need for this if I was familiar with one of the very
> few languages that handle the year value in this way (i.e. C and Java).
> Otherwise, I would not have any reason to expect anything but 00 for the
> year 2000.
>
> Your ignorance of the potential seriousness of this aspect of
> the Y2K problem would indicate that you are unqualified to judge whether
> or not I have the qualifications to write on this subject.
If you are checking a language for bugs, and you don't know the
language, you are clearly unqualified to to write on the subject. That
is clearly the case.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Thu, 27 May 1999 07:45:02 -0700
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <374D5A6E.130B4377@atrieva.com>
finsol@ts.co.nz wrote:
> The fact is that CGI shares the same Y2K
> booby-trap problem as Perl. Fixing Y2K problems is more important than
> playing stupid semantics.
While musing further:
> Your ignorance of the potential seriousness of this aspect of
> the Y2K problem would indicate that you are unqualified to judge whether
> or not I have the qualifications to write on this subject.
Please, show us your qualifications by posting some Y2K brokeness in
CGI. Then, show us how we might fix it.
Afterwards, I'm sure you will realize your gross incompetence, and go
back to the human resources department where you belong.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Thu, 27 May 1999 14:57:05 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: FAQ 4.16: Does Perl have a year 2000 problem? Is Perl Y2K compliant?
Message-Id: <53d33.858$nn.257212@news.shore.net>
In comp.lang.perl.misc finsol@ts.co.nz wrote:
: that I don't wish to debate. The fact is that CGI shares the same Y2K
: booby-trap problem as Perl. Fixing Y2K problems is more important than
: playing stupid semantics.
CGI has a y2k problem? News to me. What does CGI have to do with dates?
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Thu, 27 May 1999 08:30:08 -0500
From: jmcn@msg.ti.com (Jason McNorton)
Subject: Re: File I/O Help Needed
Message-Id: <MPG.11b704da9c67ab2c98991f@news.itg.ti.com>
In article Larry Rosler, lr@hpl.hp.com says...
> [Posted and a courtesy copy mailed.]
>
> In article <MPG.11b609dc900b8dcf98991c@news.itg.ti.com> on Wed, 26 May
> 1999 14:39:15 -0500, Jason McNorton <jmcn@msg.ti.com> says...
> ...
> > open (SAVES, ">$checkfile");
> > close (SAVES);
> >
> > As soon as I put a > so I can write to it, it croaks. If I set
> > $checkname directly equal to "/server-root/c1st/1003.chk", they both
> > work. Any ideas on why it's working for reading only, but not if I try
> > to write? Thanks a ton for any help.
>
> I have no idea, but Perl might. Why don't you let it tell you?
>
> open (SAVES, ">$checkfile") or
> die "Can't open '$checkfile' for writing. $!\n";
The problem was that it was set to perl -T
Taint problem, this lined solved it:
$ledger = $1 if $ledger =~ /(\d+)/; # untaint number
Thanks for your help everyone.
------------------------------
Date: 27 May 1999 07:21:29 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: flock and string search.
Message-Id: <374d46d9@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
"$Richy Rich$" <rich_guy@hotmail.com> writes:
: i can't find an in-depth answer to this question, so i'll go ahead
:and ask. if you can point me to a URL or info file regarding the flock
:command, then that would do,
The complete set of perl documentation is available linked in the
topmost news item of
http://language.perl.com/admin/whats_new.html
I strongly suggest you get it.
Meanwhile, here's the relevant section from the perlopentut tutorial:
File Locking
In a multitasking environment, you may need to be careful not to
collide with other processes who want to do I/O on the same
files as others are working on. You'll often need shared or
exclusive locks on files for reading and writing respectively.
You might just pretend that only exclusive locks exist.
Never use the existence of a file `-e $file' as a locking
indication, because there is a race condition between the test
for the existence of the file and its creation. Atomicity is
critical.
Perl's most portable locking interface is via the `flock'
function, whose simplicity is emulated on systems that don't
directly support it, such as SysV or WindowsNT. The underlying
semantics may affect how it all works, so you should learn how
`flock' is implemented on your system's port of Perl.
File locking *does not* lock out another process that would like
to do I/O. A file lock only locks out others trying to get a
lock, not processes trying to do I/O. Because locks are
advisory, if one process uses locking and another doesn't, all
bets are off.
By default, the `flock' call will block until a lock is granted.
A request for a shared lock will be granted as soon as there is
no exclusive locker. A request for a exclusive lock will be
granted as soon as there is no locker of any kind. Locks are on
file descriptors, not file names. You can't lock a file until
you open it, and you can't hold on to a lock once the file has
been closed.
Here's how to get a blocking shared lock on a file, typically
used for reading:
use 5.004;
use Fcntl qw(:DEFAULT :flock);
open(FH, "< filename") or die "can't open filename: $!";
flock(FH, LOCK_SH) or die "can't lock filename: $!";
# now read from FH
You can get a non-blocking lock by using `LOCK_NB'.
flock(FH, LOCK_SH | LOCK_NB)
or die "can't lock filename: $!";
This can be useful for producing more user-friendly behaviour by
warning if you're going to be blocking:
use 5.004;
use Fcntl qw(:DEFAULT :flock);
open(FH, "< filename") or die "can't open filename: $!";
unless (flock(FH, LOCK_SH | LOCK_NB)) {
$| = 1;
print "Waiting for lock...";
flock(FH, LOCK_SH) or die "can't lock filename: $!";
print "got it.\n"
}
# now read from FH
To get an exclusive lock, typically used for writing, you have
to be careful. We `sysopen' the file so it can be locked before
it gets emptied. You can get a nonblocking version using
`LOCK_EX | LOCK_NB'.
use 5.004;
use Fcntl qw(:DEFAULT :flock);
sysopen(FH, "filename", O_WRONLY | O_CREAT)
or die "can't open filename: $!";
flock(FH, LOCK_EX)
or die "can't lock filename: $!";
truncate(FH, 0)
or die "can't truncate filename: $!";
# now write to FH
Finally, due to the uncounted millions who cannot be dissuaded
from wasting cycles on useless vanity devices called hit
counters, here's how to increment a number in a file safely:
use Fcntl qw(:DEFAULT :flock);
sysopen(FH, "numfile", O_RDWR | O_CREAT)
or die "can't open numfile: $!";
# autoflush FH
$ofh = select(FH); $| = 1; select ($ofh);
flock(FH, LOCK_EX)
or die "can't write-lock numfile: $!";
$num = <FH> || 0;
seek(FH, 0, 0)
or die "can't rewind numfile : $!";
print FH $num+1, "\n"
or die "can't write numfile: $!";
truncate(FH, tell(FH))
or die "can't truncate numfile: $!";
close(FH)
or die "can't close numfile: $!";
Here's another example, this time from the DB_File manpage:
unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
print "$$: CONTENTION; must have exclusive lock!
Waiting for write lock ($!) ....";
unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
}
--tom
--
"And I don't like doing silly things (except on purpose)."
--Larry Wall in <1992Jul3.191825.14435@netlabs.com>
------------------------------
Date: 27 May 1999 07:46:49 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to write htaccess?
Message-Id: <374d4cc9@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
austin95002887@yahoo.com (Austin Ming) writes:
:How to write htaccess?
Give him an H!
Give him a T!
Give him an A!
Give him a C!
Give him another C!
Give him an E!
Give him an S!
Give him another S!
What does that write?
+------------------------------------------+
| +--------------------------------------+ |
| | +----------------------------------+ | |
| | | +------------------------------+ | | |
| | | | +--------------------------+ | | | |
| | | | | +----------------------+ | | | | |
| | | | | | +------------------+ | | | | | |
| | | | | | | +--------------+ | | | | | | |
| | | | | | | | +----------+ | | | | | | | |
| | | | | | | | | HTACCESS | | | | | | | | |
| | | | | | | | +----------+ | | | | | | | |
| | | | | | | +--------------+ | | | | | | |
| | | | | | +------------------+ | | | | | |
| | | | | +----------------------+ | | | | |
| | | | +--------------------------+ | | | |
| | | +------------------------------+ | | |
| | +----------------------------------+ | |
| +--------------------------------------+ |
+------------------------------------------+
Now, go find a better newsgroup.
--tom
--
Hi, this is Ken. What's the root password?
------------------------------
Date: Thu, 27 May 1999 13:44:23 GMT
From: sherifhanna@my-deja.com
Subject: Making Perl Wait
Message-Id: <7iji7n$l85$1@nnrp1.deja.com>
Is there any way I can make a Perl scripts stop for x number of
seconds? Is there a built-in function for that?
So something like
wait(10);
or similar...
The reason I ask is because I have to establish a PPP session through
the script, but must wait for at least 10 or 12 seconds before checking
whether the PPP session is established or not....
Thanks,
Sherif
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Thu, 27 May 1999 16:07:04 +0200
From: brad@shub-internet.org (Brad Knowles)
Subject: Re: Making Perl Wait
Message-Id: <brad-2705991607040001@brad.techos.skynet.be>
In article <7iji7n$l85$1@nnrp1.deja.com>, sherifhanna@my-deja.com wrote:
> The reason I ask is because I have to establish a PPP session through
> the script, but must wait for at least 10 or 12 seconds before checking
> whether the PPP session is established or not....
How about "sleep(10)"?
--
Brad Knowles <brad@shub-internet.org> <http://www.shub-internet.org/brad/>
<http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=0xE38CCEF1>
Are you looking for a news feed from a site in the Freenix Top 130?
If so, contact me via private e-mail for details.
------------------------------
Date: 27 May 1999 08:08:17 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Making Perl Wait
Message-Id: <374d51d1@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
Bedamned by the evil and rude Mozilla/4.0 (compatible; MSIE 4.01;
Windows NT), sherifhanna@my-deja.com blathered in comp.lang.perl.misc:
:Is there any way I can make a Perl scripts stop for x number of
:seconds? Is there a built-in function for that?
I dunno. Maybe you should search in the standard perlfunc manpage
that comes with each and every distribution of perl and is sitting
right there on your own system, which is where the standard
built-in functions are documented. If you can't find it, fire
your negligent and idiotic system administrator, then proceed to
http://language.perl.com/admin/whats_new.html and get the newest set
of docs.
We can't read manpages to you Prisoners of Bill. You have
to do your own homework.
--tom
--
If you are not part of the solution, you are part of the precipitate.
------------------------------
Date: 27 May 1999 14:23:05 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Making Perl Wait
Message-Id: <7ijkg9$22f$1@info2.uah.edu>
In article <7iji7n$l85$1@nnrp1.deja.com>,
sherifhanna@my-deja.com writes:
: Is there any way I can make a Perl scripts stop for x number of
: seconds? Is there a built-in function for that?
# o/~ Mr. Sandman, bring me a dreeeeeeam... o/~ :-)
sleep 12;
Greg
--
I considered atheism but there weren't enough holidays.
------------------------------
Date: 27 May 1999 13:14:32 GMT
From: scarblac-spamtrap@pino.selwerd.cx (Remco Gerlich)
Subject: My first working script; comments, hints?
Message-Id: <slrn7kqh3e.7c3.scarblac-spamtrap@flits104-37.flits.rug.nl>
After reading Learning Perl, a lot of messages in this group,
and those parts of the docs I needed, I wrote my first "useful"
script that was actually finished, and works. I thought I could
post it here to see if someone has useful hints, because I'm sure
there's going to be a lot wrong with it still, or at least there
will be better ways to do some things.
The script is adds random signatures to a newsgroup
post (below the "-- " and the first line that my newsreader puts
there by itself). I have files that act as .signatures in ~/.sigs.
A file ~/.sigindex is an index of the files, optionally with a regexp
that is used to check the group(s) the post goes to. All groups must
match the regexp. (It has lines like "sigvirus" and "/^nl\./ nederlands".
A line '&SIG filename' in the post selects a file by hand.
'&SIG "pattern"' greps the .sigs dir and chooses a result randomly.
Other &SIG lines cancel the sig script.
Also, if the signature file is executable, it's run, and its output
is used as the signature (for instance the level of my current
Angband character in rec.games.roguelike.angband, etc).
This is the script. Any comments on my style, or errors I've missed?
#!/usr/bin/perl -w
# init RNG
srand;
$SIGCOM = $groups = $sigfile = undef;
# for some reason I can't just use $ARGV[0] later on -
# because of using <>?
$article = $ARGV[0];
# Read it in - we need to write to it later to remove &SIG stuff
@article = <>;
# Write it back without &SIG commands, and look for Newsgroups: line
open (POST, ">$article");
foreach $line (@article) {
if ($line =~ /^&SIG(.*)$/) {
$SIGCOM = $1;
} else {
print POST $line;
if (!defined($groups) and $line =~ /^Newsgroups: (.*)$/) {
$groups = $1;
}
}
}
# It has to be closed here because other programs may use
# it before we write to it again (see below)
close (POST);
# Get individual group names (in case of crossposts)
@groups = split(/,/,$groups);
# Read the sig index file
open (SIGINDEX, "$ENV{'HOME'}/.sigindex") or die "No .sigindex: $!";
@sigindex = <SIGINDEX>;
foreach $line (@sigindex) { chop $line; }
close (SIGINDEX) or die "Closing .sigindex failed: $!";
# Now, find a signature file to use based on &SIG, the newsgroups,
# and the sig index.
if (defined($SIGCOM)) {
$success = 1;
if ($SIGCOM =~ / ([^\"\']+)/) {
# Just a string without quotes, use that as filename
$sigfile = "$ENV{'HOME'}/.sigs/$1";
} elsif ($SIGCOM =~ / \"(.+)\"/) {
# A string within double quotes - grep to find files
# XXX - this will include scripts that are intended to be run -
# So put an explanation for those in their comments, and use
# no readable code in them :)
$filenames = join(" ",glob ("$ENV{'HOME'}/.sigs/*"));
@files = split(/\n/,`grep -l $SIGCOM $filenames`);
if (@files) {
$sigfile = $files[rand(@files)];
}
} else {
# Otherwise (&SIG but nothing recognizable) - no sig
}
} else {
# No &SIG seen - pick random
# Try to find a suitable random sig file, but stop trying after
# 10 failures
$success = 0;
for ($i=0; $i<10 and !$success; $i++) {
# select a sigfile to try out
$try = $sigindex[rand(@sigindex)];
# Sig index lines may be either just a filename, or a regexp followed
# by a filename.
if ($try =~ /^\/(.*)\/ (.*)/) {
$regexp = $1; $sigfile = "$ENV{'HOME'}/.sigs/$2";
} else {
$success = 1; $sigfile = "$ENV{'HOME'}/.sigs/$try"; last;
}
# All the newsgroup names have to match the regexp.
$success = 1;
foreach $gr (@groups) {
unless ($gr =~ /$regexp/) {
$success = 0;
last;
}
}
}
}
print "Sigfile: $sigfile";
# If a signature was found, add it to the post.
if ($success and defined($sigfile)) {
use File::stat;
$st = stat($sigfile) or die "Huh? Sigfile gone: $!";
if ($st->mode & 0111) {
# file executable? then call it with $article as argument.
# Since this may change the article, we had to close that file
# earlier.
@siglines = `$sigfile $article`
}
else {
open (SIGFILE,"$sigfile")
or die "No sigfile $sigfile: $!";
@siglines = <SIGFILE>;
close (SIGFILE) or die "Sigfile close failed: $!";
}
# Print the signature, finally.
open (POST,">> $article") or die "Couldn't open article: $!";
foreach (@siglines) {
print POST $_;
}
close (POST) or die "Article close failed: $!";
}
--
Remco Gerlich, scarblac@pino.selwerd.cx
------------------------------
Date: Thu, 27 May 1999 14:27:26 GMT
From: sbeaulieu@my-deja.com
Subject: Perl call to c/c++ DLL
Message-Id: <7ijko9$n7n$1@nnrp1.deja.com>
Is it possible for Perl to call c/c++ dlls? If
it is, then where can I find information on it?
Stephen
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 27 May 1999 07:43:59 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl script as an executable
Message-Id: <374d4c1f@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, therzog@knotech.com (Tim Herzog) writes:
: read STDIN, $_, $ENV{'CONTENT_LENGTH'};
That code is evil and wrong. You are, in effect, recreating
a broken wheel.
--tom
--
"Usenet is like a herd of performing elephants with diarrhea --
massive, difficult to redirect, awe-inspiring, entertaining, and a
source of mind-boggling amounts of excrement when you least expect
it." --gene spafford, 1992
------------------------------
Date: Thu, 27 May 1999 15:08:00 +0200
From: "Vincent Vanbiervliet" <vincent_vanbiervliet@be.ibm.com>
Subject: Re: please test my new site..
Message-Id: <374d3450@news.uk.ibm.net>
Looks good, but as a nitpicker, I need to make some comments ;-)
1. If you don't enter anything in the 'other' field, and press the button,
you don't get an errormessage.
2. The 'Get Results' window shows only the percentages of 'Soda' and 'Pop',
not for 'Other'. Make the window bigger, the font smaller, or make it
scrollable. Or...
3. ... I think results like 65.22%/21.74% make more sense to most people,
and are actually more readable than 65.2173913043478%/21.7391304347826%.
(This has as a plus that - at least on my screen (1024x768) the results for
one word will be on one line...)
Vincent.
Dan Foley <djfst34@pitt.edu> wrote in message
news:7iimor$g8t$1@usenet01.srv.cis.pitt.edu...
> Made with javascript/html/perl
>
> (that is why i am posting on these 3 newsgroups)
>
> it's a simple survey.. to figure out who says soda and who says pop. can
> everyone please take a few seconds to answer this one question survey and
> also to let me know if u find any bugs along the way.
>
> Currently i am just gathering data.. soon i wish to display the results
> graphically on a map of the us.. (i guess demographically).. if u might be
> able to help out with that. let me know..
>
> to take the survey and test my site go to
>
> www.pitt.edu/~djfst34/surveys/sodapop.html
>
>
>
> --
> ------------------------------------------------------------
> - Dan Foley -
> - music, resume, more on me -
> - www.pitt.edu/~djfst34 -
> ------------------------------------------------------------
>
>
------------------------------
Date: 27 May 1999 09:27:48 -0400
From: Lewis Perin <perin@panix7.panix.com>
Subject: Re: please test my new site..
Message-Id: <pc7btf6iqwb.fsf@panix7.panix.com>
"Dan Foley" <djfst34@pitt.edu> writes:
> Made with javascript/html/perl
>
> (that is why i am posting on these 3 newsgroups)
>
> it's a simple survey.. to figure out who says soda and who says pop. can
> everyone please take a few seconds to answer this one question survey and
> also to let me know if u find any bugs along the way.
>
> Currently i am just gathering data.. soon i wish to display the results
> graphically on a map of the us.. (i guess demographically).. if u might be
> able to help out with that. let me know..
>
> to take the survey and test my site go to
>
> www.pitt.edu/~djfst34/surveys/sodapop.html
As HTML it's busted: no labels on buttons so for non-graphical
browsers it's useless.
Cheers, Lew
------------------------------
Date: 27 May 1999 07:35:10 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: popgrep (was: please test my new site..)
Message-Id: <374d4a0e@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, "Dan Foley" <djfst34@pitt.edu> writes:
:Made with javascript/html/perl
Well, I'm afraid it fails miserably. Many people don't permit javascript.
There's no for it here that I can see it. Please fix your site.
And while you're at it, you should probably read my design tips at:
http://language.perl.com/misc/div-www.html
You should also use these categories:
Soda
Pop
Sodapop
Soft Drink
Apparently you don't know about my myriad popgrep demos.
They're at http://mox.perl.com/misc/popgrep/
Here's one:
#!/usr/bin/perl
# popgrep5 - grep for abbreviations of places that say "pop"
# version 5: use spiffy new qr// operator, with /i flag even
use 5.005;
@popstates = qw(CO ON MI WI MN);
@poppats = map { qr/\b$_\b/i } @popstates;
while (defined($line = <>)) {
for $patobj (@poppats) {
print $line if $line =~ /$patobj/;
}
}
You should also realize that 1) Canadian postal codes look different
than they do in the United States and 2) Other people speak English,
too -- like, for example, the English. :-)
For the record, "pop" is any pre-made crud from a can or bottle, whereas
"soda" is either icky clear soda water (think "Campari and Soda"),
or else is that divine conconction you get made fresh with sweet syrup
and soda water down at the soda fountain by the soda jerk, and occurring
in such awesome instantiations cherry soda, vanilla soda, lime soda, or
chocolate soda. And brewed root beer or ginger ale is not technically
either, but are nonetheless soft drinks.
--tom
--
"Contempt, rather than celebration, is the proper response to
advertising and the system that makes it possible." --Neil Postman
------------------------------
Date: Thu, 27 May 1999 09:19:17 -0400
From: "Carey Barnett" <cbarnett@idirect.com>
Subject: Re: Reading text file
Message-Id: <374d463e.0@diana.idirect.com>
Print the first half of the Web page using the 'here' print method, then...
while(<F>){print; print "\n";} # Print each line one at a time.
OR
@a = <F>;
while (<@a>){$_ .= "\n";} # Append a carriage return to each line.
OR
@a = <F>;
while (<@a>){$_ .= '<BR>';} # Append an HTML line break to each line.
Print the second half of the Web page.
------------------------------
Date: 27 May 1999 07:36:41 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Reading text file
Message-Id: <374d4a69@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
therzog@knotech.com (Tim Herzog) writes:
:Wrap the file in <PRE> tags, like this:
That's not sufficient. You didn't html escape.
And this is unrelated to perl.
--tom
--
Eighty percent of air pollution comes from plants and trees.
--Ronald Reagan, famous movie star
------------------------------
Date: 27 May 1999 07:42:44 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Reading text file
Message-Id: <374d4bd4@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, "Robert" <ducott@geocities.com> writes:
:Does anyone know how I can tell the code to read the text file and print
:it's contents in the same format as it's written in the text file.
^^^^ ^^^^
Sir, I'm afraid your genitives are missing.
A: It's not that it's a mortal sin, it's just that its spelling sucks.
C: Whose spelling?
A: Its spelling.
C: It's spelling what?
A: No, just its spelling.
C: What's it spelling?
A: Spelling? It's not spelling.
C: YOU SAID IT WAS SPELLING SUCKS!
A: No, I never said it was spelling anything.
I merely remarked that its spelling sucks.
C: There! You said its again.
A: No I didn't, I said its spelling. "It" doesn't have an "again".
And you're the one who said it's spelling.
C: I wish you would tell me what it's spelling.
A: Who's spelling anything?
C: I don't even know whose spelling we're using! Your spelling!
A: No, I'm not Spelling; I'm Abbott. You're the one whose spelling sucks,
and also the one who's spelling sucks.
--tom
"A foolish consistency is the hobgoblin of little minds, adored by
little statesmen and philosophers and divines. With consistency a
great soul has simply nothing to do." --Ralph Waldo Emerson
--
X-Windows: A moment of convenience, a lifetime of regret.
--Jamie Zawinski
------------------------------
Date: Thu, 27 May 1999 10:22:52 -0400
From: Simon Rosenthal <srosenthal@northernlight.com>
To: Greg McCann <gregm@well.com>
Subject: Re: Safe.pm necessary for secure CGI?
Message-Id: <374D553C.AA7CA0DA@northernlight.com>
Well, using Safe.pm is one thing that you can do, but there are other,
far more important, security holes in the CGI environment that Perl is
*very* well equipped to deal with, using mechanisms such as taint
checking.
Your so-called "expert" may know about internet security, but his
statement on Perl being full of security holes doesn't give me any warm
fuzzies about his expertise in Perl.
Mark_Jason Dominus gave an execellent tutorial on Web Site Security at
the recent O'Reilly Conference, which I haven't been able to find
on-line. The WWW Security FAQ
(http://www.w3.org/Security/faq/www-security-faq.html#contents)
addresses the same set of issues, including a section on using Perl.
- Simon
Greg McCann wrote:
>
> I just talked to an internet "security expert" who said that I should be using
> Safe.pm for secure cgi programming in Perl, and that not using it would make my
> system vulnerable - that Perl "as-is" is full of security holes. Now I'm
> worried. Under what circumstances, if any, is this true? I don't see anything
> in the description of Safe.pm that relates specifically to cgi programming.
>
> Thanks,
>
> Greg
------------------------------
Date: Thu, 27 May 1999 14:02:06 GMT
From: izzac@my-deja.com
Subject: thread vs process
Message-Id: <7ijj8t$m57$1@nnrp1.deja.com>
I have to create bots that take a DB of URLs and make a GET(with
libwww) on each to find any informations. I would like at least 8 to 10
GET performing at the same time. This works well with the module IProc
that allows to manage processes and see when they have finished or kill
them when they timeout.
But, I also know that libwww allows parrallel GET, but I read that
these threads do not perform very well (maybe my sources are not
good!?).
So, which are the advantage of threads, and those of proccess ?
Is it more easy to manage many process or many threads ?
And what about the memory or cpu ?
For the informations that should be passed to my process I use files
and the result of the search is written also in the same file. Is there
a better way possible ?
If anybody can help me, this would be very appreciated!!:o)
thanks
Jonthan.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Thu, 27 May 1999 16:11:23 +0200
From: Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
Subject: Re: undef of namespaces
Message-Id: <374D528B.BD50179E@lublin.zrz.tu-berlin.de>
Marc Dietrich wrote:
[...]
> I'm going to use the hint of Anno (thanks to you) for now. Perhaps some
> developers should take a look at this problem in future versions of
> perl.
It wasn't a very good hint, though. As others have remarked, it is
probably not a good idea to clean a name space like that. But if
you must, use delete instead of where I used undef in the example.
Undef leaves the keys (i.e. varable names, in this case) in a hash
table,
it only undef's the values.
While perl seems to cope with the situation, I shudder at the thought of
an existing variable with an undefined typeglob. A surprise waiting
to happen...
Anno
------------------------------
Date: 27 May 1999 07:54:47 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: using zipcodes to graphically desplay survey results online
Message-Id: <m1emk2lg08.fsf@halfdome.holdit.com>
>>>>> "Dan" == Dan Foley <djfst34@pitt.edu> writes:
Dan> I wish to display the results geographically baised on the
Dan> zipcode that goes along with each answer.
Dan> my thought is that i am going to need some exteral database of
Dan> zipcode and somehow corrorlate them to a map. My current thought
Dan> is that The only way to really do this is with a zipcode data
Dan> base that gives longitude and latitude.. then i can just plot the
Dan> results on my map.. no matter how zoomed in or out you are.. i
Dan> can always have an equation that plots the longitude and latitude
Dan> correctly..
Dan> i looked on the web and see such databases cost money, and this
Dan> is just a pet project of mine.. so is there another way..?
I've seen at least one program ask www.mapquest.com for a map based on
a zipcode, and then decode some of the URLs to extract its latitude
and longitude.
There was also a geo server at U-Buffalo that accepted queries for
information about a zip code. Dunno if that's still there.
Dan> Also.. lets say i did get the longitute and latitute... how would
Dan> i plot this.. do i do it real time each time a user request the
Dan> results? plot an overlay over a map?? I can't think of how else
Dan> i'd do it.. (javascript can do that. but we are talking a
Dan> database search for each entry.. and then a plot.. how long might
Dan> this take.. ?)
It'll probably take too long to requery all the Zipcode items if you
use an external server, so you should probably record zipcode/lat/lon
in the database. Building the image on the fly is no biggy... I show
how to do that on <http://www.stonehenge.com/merlyn/WebTechniques/>.
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 27 May 1999 07:11:03 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: why doesn't my first program work?? (ok , third or something)
Message-Id: <374d4467@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, therzog@knotech.com (Tim Herzog) writes:
:The volume of perl documentation doesn't mean that
:the language is accessible. Quite the contrary.
I guess you'd say the same thing about the Oxford English Dictionary,
the Encyclopaedia Britannnica, Tolstoy's War and Peace, Thoreau's
Walden, Bach's Bm Mass, Mendelssohn's Midsummer Night's Dream, or
Mozart's Requiem.
Too many words. Too many notes.
Too much documentation. Oh good. Let's delete most of it then.
Nominations please? I'm in a position to fix this problem. Please
tell me which man pages I should delete. I'm sure people will
benefit greatly from knowing less. Ignorance has always helped
in the past.
--tom
--
"Software engineering phase plans are something you make so your manager
can explain to his manager how things are going"
--Rob Pike (On the subject of managerial "bullshit")
------------------------------
Date: 27 May 1999 07:04:29 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: workarounds for prototypes
Message-Id: <374d42dd@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Gareth Rees <garethr@cre.canon.co.uk> writes:
:Tom Christiansen <tchrist@mox.perl.com> wrote:
:> a function that takes a Foo object and a Bar object as
:> its two arguments
:
: use Class::Multimethods;
: multimethod foo => qw(Foo Bar) => sub { ... }
No, sir. That is not a prototype check! That's just a run-time
hack. If you don't check prototypes at compile-time, you aren't
checking prototypes.
And at this stage, it may remain an open topic whether Class::Multimethods
pertains more to the solution set than it does to the problem set. :-)
Another rich topic open for discussion is where the formalists'
pre-condition and post-condition contracts, typically implemented in
assert-style statements, fall into the picture.
--tom
--
Nuclear war doesn't prove who's Right, just who's Left (ABC news 10/13/87)
------------------------------
Date: 27 May 1999 13:48:27 +0200
From: mriedel@neuearbeit.de (Marko R. Riedel)
Subject: Re: writing binary stuff back to a browser, funky format
Message-Id: <lz3e0i3f90.fsf@linux_sexi.neuearbeit.de>
#! /usr/bin/perl -w
#
@data=('doobie', 'boogie');
$packed=''; foreach(@data){
# replace 'l' with 'N' or 'V' if necessary
$packed .= pack 'la*', length $_, $_;
}
$packed =~ s/(.)/unpack('H2', $1)/eg;
print "$packed\n";
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". 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". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5802
**************************************