[18035] in Perl-Users-Digest
Perl-Users Digest, Issue: 195 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 1 18:11:25 2001
Date: Thu, 1 Feb 2001 15:10:20 -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: <981069020-v10-i195@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 1 Feb 2001 Volume: 10 Number: 195
Today's topics:
Re: printf and leading zeros <mischief@velma.motion.net>
Problem with Socket.pm elton_taupin@my-deja.com
Re: Question on appending to file <mischief@velma.motion.net>
Re: Question on appending to file dtbaker_dejanews@my-deja.com
race condition or lock problem <johnm@acadiacom.net>
Re: RegExp: Find anything except... <elijah@workspot.net>
search index/stop words/performance <theclyde@mindless.com>
Re: search index/stop words/performance <tore@extend.no>
Re: searching text files using NEAR (proximity) <tore@extend.no>
Re: secure form dtbaker_dejanews@my-deja.com
Re: Seeking timezone conversion advice <ddunham@redwood.taos.com>
Re: sorting IP addresses <russ_jones@rac.ray.com>
stupid eval tricks (Weston Cann)
Re: stupid eval tricks (Craig Berry)
Re: The Best News Publishing Perl Script (Weston Cann)
Uploading files <I.J.Dash@cs.cf.ac.uk>
Re: Uploading files dtbaker_dejanews@my-deja.com
Win32::Service::GetStatus method <doronn@nrt.co.il>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 01 Feb 2001 21:26:55 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: printf and leading zeros
Message-Id: <t7jl4vcv8iq4c3@corp.supernews.com>
Ilmari Karonen <iltzu@sci.invalid> wrote:
> In article <t7go7oms60ui6e@corp.supernews.com>, Chris Stith wrote:
>>
>>Does your answer look anything like this?
>>
>>my $number = 0.33;
>>my $number_like_string = sprintf("%s", $number);
>>$number_like_string =~ s/0(?=\.)//;
>>print "$number_like_string\n";
> I hope not. That second line is an expensive no-op, and the regexp
> probably needs anchoring to stop "10.05" becoming "1.05".
Sorry, I went away into a land where languages require casts there
for a second. That second line is indeed a no-op in Perl.
> (my $string = $number) =~ s/^0\././;
As for anchoring the regex, it is more general to do so, and generality
is a good idea. The question, though was how to get rid of a leading
zero before a decimal point. My code did that, but it didn't make _sure_
the zero was a leading zero. Admittedly, it does make more sense to put
all the work in the regex for ease of readability and simpler code.
> Please ignore Godzilla and its pseudonyms - do not feed the troll.
This last one is very good advice indeed.
Chris
--
Christopher E. Stith
If they can get you asking the wrong questions, they don't
have to worry about the answers.
-- Thomas Pynchon, Gravity's Rainbow
------------------------------
Date: Thu, 01 Feb 2001 21:45:53 GMT
From: elton_taupin@my-deja.com
Subject: Problem with Socket.pm
Message-Id: <95clee$eks$1@nnrp1.deja.com>
The problem arises when I try to load in a couple network parameters
with Socket.pm. Socket.pm won't work since the server was moved
and put onto a new network connection.
I can make socket connections by manually inserting the number in code
for
ex:
socket($FS, 2, 2, $proto)
but should be automatic like:
socket($FS, PF_INET, SOCK_STREAM, $proto)
So the script can work on and computer without me hard coding in the
values. The scripts will make socket connections
fine if I hard coded the numbers in.
How do I fix the Socket.pm up I have installed perl 5.6.0 and the
version that sco has prebuilt for UnixWare 5.005_03 built for i386-svr4.
The error I get when I try to get the value for PF_INET or SOCK_STREAM
using Socket.pm is : Segmentation fault (core dumped)
Shaun
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 01 Feb 2001 21:06:22 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Question on appending to file
Message-Id: <t7jjuecjhtki4d@corp.supernews.com>
John Tutchings <ccx138@coventry.ac.uk> wrote:
> difference between
> $junk = <FILE>;
> and
> @junk = <FILE>;
Also a big difference between:
{
$junk = <FILE>;
}
and
{
undef $/;
$junk = <FILE>;
}
which may be causing some confusion to those who vaguely remember using
an undefined input record separator. It's pretty obvious, though, that
if
while( <FILE> ) {
}
grabs lines one at a time then
$junk = <FILE>;
should too, since they use the same operator. You just have to look
carefully enough to realize it _is_ the same operator. The magic in
the construct
while( <FILE> ) {}
is that it automatically uses the $_ variable inside the loop, not that
it changes how many lines are used per loop iteration.
Chris
--
Christopher E. Stith
Parking for people we like only. All other vehicles will be vandalized.
------------------------------
Date: Thu, 01 Feb 2001 21:23:40 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Question on appending to file
Message-Id: <95ck4e$d4a$1@nnrp1.deja.com>
In article <3A792DF1.52E4F445@free.fr>,
Jerome Abela <Jerome.Abela@free.fr> wrote:
> No, <FILEHANDLE> only reads the first line in a scalar context.
> Double read the code. It reads one line, and checks whether there is
> another one. Here are the relevant lines again:
> <FILE>;
> if(!<FILE>) {
>
----------------
hhhmmm, ok! learn something every day. ;)
D
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 01 Feb 2001 22:56:55 GMT
From: "John Michael" <johnm@acadiacom.net>
Subject: race condition or lock problem
Message-Id: <95cpjn$k6h@dispatch.concentric.net>
I have a script that checks for hit bot attacks of an .htpasswd file in
brute force attempts. The script will email me when an attack occurs.
I am using a semaphore.file as a lock file in an attempt to prevent multiple
emails from occurring, because several files have to be updated.
I use this at the beginning of the script:
use strict;
use Fcntl qw(:DEFAULT :flock);
open (EL_LOCK, ">>el_sem.file") ||
&error('file_open_failure','el_sem.file');
flock (EL_LOCK, LOCK_EX) || &error('file_lock_failure','el_sem.file');
then the script stuff and regular file stuff
and then I close the lock file when exiting.
close(EL_LOCK);
The &error subs print out ht error and exit the script.
However, the script will still send several emails. I am getting the
impression that a race condition is occuring, because the LOCK file is not
preventing multiple occurances of the script from running.
Do lock files work?
If they do, why is mine not?
One of the files documents the ip.
Therefore, If the ip is already documented, the script will not send the
email. I get multiple emails.
Is there a way to keep more than one occurance of a script from running?
Would it be better to use maybe some kind of external file as a switch
maybe.
I could keep a 1 or 0 in the file that other files would read. If a 0 is
present, the other files would then exit. Whenever the script running
exits, it could print out a 1 to the switch file.
Or I sould change the permissions of a file or something and have scripts
exit if they can't read it.
What should I do?
thanks
John Michael
------------------------------
Date: 1 Feb 2001 19:46:06 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: RegExp: Find anything except...
Message-Id: <eli$0102011442@qz.little-neck.ny.us>
In comp.lang.perl.misc, Costis Vezeridis <vezerid@ac.anatolia.edu.gr> wrote:
> > How does it "not always seem to work reliably"? Does it perhaps fail
> > to match more than one line? Did you write ".*?"? Did you forget /s?
> I mean that sometimes the patterns using ? indeed act greedy. For
> example, m/\(.+?\)/ would sometimes match with another closing
> parenthesis and not the immediately following one. When I switched to
> m/\([^\)]+?\)/, it would safely match only neighboring paren's.
I doubt those two differ in what they match. The problem comes in
when you add more context. (And for that reason I am loathe to use
non-greedyness in my regular expressions.)
Elijah
------
sub S(){@s=caller($/);$s[3]=~s s\w+:+ss&&print$s[3].q. .}$/=$^=~s/\S+/\n/;
$_="Just (eli) Another (the) Perl (bearded) Hacker";sub s($){eval$_[0];$/}
while(s&&&&& &s(qq&sub$^&.$&.q&{\&S}&)&& &{$&}&&s&&&){$/}$\=$^;print"\b,";
------------------------------
Date: Thu, 01 Feb 2001 21:34:07 GMT
From: Craig Bennett <theclyde@mindless.com>
Subject: search index/stop words/performance
Message-Id: <udN5OhwMZo05iW+zr9kte7n9C=DJ@4ax.com>
My jokes site has 26 directories (some have subdirectories). They are
filled with jokes as .txt files. I wrote a program to create an index file
for search purposes, with a modest stoplist. The file is set up with one
joke per line (see below). The index file is 500k
directory/filename.ext|Keyword1Keyword2keyword3
It does the search by opening the file, then going through each line to see
if the requested keywords are in it. The search is working, but it is a bit
slower than i would like it.
Is there any easy way for me to increase the speed? Is having a large file
slowing it down? Would using several smaller index files increase the
speed?
Craig
| Craig Bennett <theclyde@NOSPAMmindless.com>
| TheClyde's Humor Archive: http://www.pangea.ca/~theclyde/jokes
| (remove the NOSPAM to email me)
------------------------------
Date: Thu, 1 Feb 2001 23:19:12 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: search index/stop words/performance
Message-Id: <MPG.14e3ff4aec4496998987d@news.online.no>
In article <udN5OhwMZo05iW+zr9kte7n9C=DJ@4ax.com>,
theclyde@mindless.com says...
> Is there any easy way for me to increase the speed? Is having a
> large file slowing it down? Would using several smaller index
> files increase the speed?
No. It's better to have one large file [1] than many small files. I
created a script which searched through an 1 MB text file in less than
a second, so you should think of optimizing your search routine
instead. :-)
[1] As long as the large file isn't *too* large. If you know that your
index files will - or can - fill up too much of the memory, you should
consider smaller files *or* reading chunks of it (instead of everything
into the memory at once).
--
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
------------------------------
Date: Thu, 1 Feb 2001 23:01:51 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: searching text files using NEAR (proximity)
Message-Id: <MPG.14e3fb3ba02e271298987c@news.online.no>
In article <95c7is$f9$1@nnrp1.deja.com>, timur@lbri.lionbioscience.com
says...
> I was looking for Perl modules that can search text files
> using NEAR, AND, OR, NOT.
As far as I remember, Text::Query does all this (and maybe even more).
You can find it on CPAN (http://www.cpan.org/).
--
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
------------------------------
Date: Thu, 01 Feb 2001 21:38:41 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: secure form
Message-Id: <95cl0v$e50$1@nnrp1.deja.com>
In article <kyde6.76733$ew1.4788760@news.infostrada.it>,
"Pier Paolo" <paolo@eurotime.it> wrote:
> i need a form to send to my e-mail some info and a message of a
client.
> This form have to be secure,therefore must be impossible to send html
> commands that can crash the server.
> It've to handle also a java and javascript data.
-----------
you need to re-think your design a little. If you are sending sensitive
data, you probably DONT want to use email. Having a form on a secure
server does you NO GOOD if you email out the data insecurely. You would
probably be better of leaving the sensitive data on the SSL server and
providing an .htaccess password protected interface for your client to
look at it. Send a "notice" email informing the client of new data, but
dont send the secure data via email.
as far as stripping input of "bad" characters, the quotemeta() function
may help you out.
D
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 01 Feb 2001 19:14:40 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Seeking timezone conversion advice
Message-Id: <AAie6.16$ns.43035@news.pacbell.net>
James Weisberg <chadbour@wwa.com> wrote:
> You misunderstood me. I realize setting $ENV{TZ} is not a system
> call or a clock change.
>>It's just that whenever you use localtime (or timelocal) the TZ variable
>>is used for the conversion.
> Right, and *those* are system calls! The two functions I have
> proposed made *no* system calls.
Okay.
> $DST{2005} = [20050403, 20051030]
> which represents the first Sunday in April and the last Sunday in
> October for 2005. Of course, it would be a simple matter to write a
> function which computed these two dates for a given year, but obviously
> a direct lookup is *much* faster. Consider looking up whether or not
> a given date is in DST for a given year for hundreds of thousands of
> records. With the above, I can do:
> my($YYYY, $MM, $DD) = unpack("a4a2a2", $date);
> if ($date < $DST{$YYYY}[0] || $date > $DST{$YYYY}[1]) {
> # NOT in Daylight Savings Time for $YYYY
> }
> Piece of cake eh? And fast! One of the reasons I store dates in
> the form YYYYMMDD is to ensure $date2 > $date1 if $date2 appears on
> the calendar *after* $date1.
Gotcha. I didn't remember you saying that you were looking for high
performance from your solution. To me, you're trading maintainability
(due to having to create the %DST hash) for speed. I'd rather not do
that. The DST is stuff maintained for me in the OS libraries, and the
system call isn't that much slower.
I did a Benchmark. For 10 iterations of each method running on 5000
random dates, I got this...
Benchmark: timing 10 iterations of lookup, syscall...
lookup: 1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU)
syscall: 5 wallclock secs ( 4.84 usr + 0.00 sys = 4.84 CPU)
So only about a factor of 5.
> Not thinking that at all. I'm thinking that changing the working
> environment of the program running is "hokey". In fact, to make any
> conversion, you'd first have to save the original timezone in a
> temporary variable and restore it before the return:
> use Time::Local;
> # 00:00 Jan 1 2001
> my $etz = $ENV{TZ}; # copy of ENV timezone
> my @start_time = ( 0,0,0,1,0,2001);
> $ENV{TZ} = "GMT0BST"; # from timezone
> my $time = timelocal(@start_time);
> $ENV{TZ} = "EST5EDT"; # to timezone
> print scalar (localtime($time));
> $ENV{TZ} = $etz; # restore ENV timezone
> Otherwise, you'd leave the working environment of the program in
> the EST5EDT timezone, which could have horrible results if the whole
> point was to translate from a variable timezone to whatever $ENV{TZ}
> is the machine the conversion takes place on. Frankly, if you don't
> consider the ying-yang of $ENV{TZ} "hokey", then you must be some
> kinda hack programmer (and I don't mean that as a complement).
It's the only way I know of to access the system libraries for timzone
information.
I'd be happier if the perl localtime() had a 2 argument form so that
$ENV{TZ} didn't have to be manipulated directly.
$dst = (localtime($time, "US/Eastern"))[8];
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Thu, 01 Feb 2001 13:56:51 -0600
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: sorting IP addresses
Message-Id: <3A79BF83.3022E544@rac.ray.com>
mike_solomon@lineone.net wrote:
>
> I have written a script to sort a list of IP addresses that I take
> from an Access database.
>
Well, I just happened to have a need to sort some IP's today, and then
I accidentally had some time to screw around with it, and I came up
with this:
(typed from a program that worked, NOT cut and pasted!)
@sorted = sort {
pack('C4',split('\.',$a))
cmp
pack('C4',split('\.',$b))
} @unsorted;
Anyway, it does a lot of splitting and packing, but it does work.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Cacatne ursus in sylvis? - Ovid
------------------------------
Date: Thu, 01 Feb 2001 21:12:33 GMT
From: iowa88_song88.remove_eights@hotmail.com (Weston Cann)
Subject: stupid eval tricks
Message-Id: <iowa88_song88.remove_eights-0102011420490001@205.184.122.221>
I've been trying to figure out a way to have perl:
1) read a file into a string
2) scan that string for any perl variables that exist
in the current block
3) replace those variables with their values
Now, what I've been doing is something like this:
$filestr = slurp($filename); # slurp puts the whole file into a string
$filestr =~ s/\$title/$title/g;
$filestr =~ s/\$ENV{'QUERY_STRING'}/$ENV{'QUERY_STRING'}/g;
$filestr =~ s/\$muck/$muck/g;
Which is OK, and I don't mind it too much, it's just that
any time I want another variable scanned for and replaced
I have to add another $filestr =~ s/\$blah/$blah/g line to
my program. This is perl. There's got to be another (better?)
way.
So I thought "hey! eval!" and tried this:
$filestr = slurp($filename);
$scannedStr = eval($filestr);
print $scannedStr;
Hmmmm. Errors right and left from the eval. I "man perlfunc" and
find the documentation on eval. It returns the value of the last expression
evaluated. So maybe I need to make sure it sees the whole file as a
double-quoted string to be valuated.
OK, how about this:
$filestr = slurp($filename);
$strToScan = "\"$fileStr\"";
$scannedStr = eval($strToScan);
print $scannedStr;
Hooray! It seems to work.
So now, I ask:
Are there other ways to do this?
Are they cooler or do they have any advantage over the way I've presented?
=================================================================
"The best laid plans of mice and men are about equal."
iowa_so8ng@hot8mail.com
Address is spam repelant. Remove eights to reach me.
------------------------------
Date: Thu, 01 Feb 2001 22:11:26 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: stupid eval tricks
Message-Id: <t7jnoer0jjmqff@corp.supernews.com>
Weston Cann (iowa88_song88.remove_eights@hotmail.com) wrote:
: I've been trying to figure out a way to have perl:
:
: 1) read a file into a string
: 2) scan that string for any perl variables that exist
: in the current block
: 3) replace those variables with their values
perldoc -q 'expand variables'
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "When the going gets weird, the weird turn pro."
| - Hunter S. Thompson
------------------------------
Date: Thu, 01 Feb 2001 20:41:26 GMT
From: iowa88_song88.remove_eights@hotmail.com (Weston Cann)
Subject: Re: The Best News Publishing Perl Script
Message-Id: <iowa88_song88.remove_eights-0102011349430001@205.184.122.221>
In article <3a709614.49866524@news.telepac.pt>, ed_energy@hotmail.com wrote:
> Hello all,
> (please sorry for my bad english)
>
> What's the best script for news publishing? (free or commercial)
>
> We need a powerfull script to do that. We need a script with the
> following fectures:
>
> - Put fotos (one or two) on the article
> - support for multiple colaborators
> - search engine
> - archive articles
> - multiple categories
> - possibility to comment the articles
>
> A script like this exists out there?
>
Sort of hard to say.
I'd suggest looking into Slash -- the code slashdot.org is based on.
I think the URL is http://slash.net or slashdot.net slashcode.net. Or
if those are all wrong, then just look for a link of slashdot.org.
Zope (http://www.zope.org) now supports perl.
And you may look into NewsPro; least powerful of options I have
suggested here, but maybe it will fit you.
Beware: all of these will take some investment to learn. Zope is
probably deepest, but since they're all open source, they're extensible
to those wanting to put in the time.
=================================================================
"The best laid plans of mice and men are about equal."
iowa_so8ng@hot8mail.com
Address is spam repelant. Remove eights to reach me.
------------------------------
Date: Thu, 01 Feb 2001 19:17:49 GMT
From: Ian Dash <I.J.Dash@cs.cf.ac.uk>
Subject: Uploading files
Message-Id: <95ccoh$5p0$1@nnrp1.deja.com>
Hi
Im trying to upload files onto my unix space via the use of Perl. I my
HTML sorted out with the <input type=file> tags etc. But its the Perl
side of things I cant do. I have looked at some of the scripts around
on the net, some of them throw up errors in the console and others just
do nothing at all when run in a web browser. Anyone who can help me?
Please!!!
Ian
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 01 Feb 2001 21:25:22 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Uploading files
Message-Id: <95ck7j$dea$1@nnrp1.deja.com>
In article <95ccoh$5p0$1@nnrp1.deja.com>,
Ian Dash <I.J.Dash@cs.cf.ac.uk> wrote:
> Hi
>
> Im trying to upload files onto my unix space via the use of Perl. I my
> HTML sorted out with the <input type=file> tags etc. But its the Perl
> side of things I cant do. I have looked at some of the scripts around
> on the net, some of them throw up errors in the console and others
just
> do nothing at all when run in a web browser. Anyone who can help me?
> Please!!!
-------------------
try using deja.com search on the word "upload". detailed solutions and
examples have been posted to this group many times.
Dan
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 1 Feb 2001 00:52:23 +0200
From: "Doron Nissimi" <doronn@nrt.co.il>
Subject: Win32::Service::GetStatus method
Message-Id: <95a4vc$gcs$1@news.netvision.net.il>
When I stop a service, and then run the GetStatus() method, it returns the
value '1' which means that the service has been stopped. This value is
returned immediately after the request is made to stop the particular
service.
However, some services take several seconds, or even minutes before they are
actually stopped, leaving a margin of error for the value GetStatus()
returns.
The same goes for starting a service...
Is there a way to know if the service is 'being stopped' or 'being started',
but not necessarily 'stopped' or 'started' yet???
Thanx!
Doron
------------------------------
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 V10 Issue 195
**************************************