[13770] in Perl-Users-Digest
Perl-Users Digest, Issue: 1175 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 21:51:04 1999
Date: Wed, 27 Oct 1999 18:22:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941073724-v9-i1175@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 27 Oct 1999 Volume: 9 Number: 1175
Today's topics:
Cannot assign the null string to a hash element <furioag@spin.it>
Re: Cannot assign the null string to a hash element <aqumsieh@matrox.com>
Re: Cannot assign the null string to a hash element (Bart Lateur)
CDONTS and Perl? pinkelma@my-deja.com
CGI - Recovering from interrupts with signals mike_lottridge@mentorg.com
Re: CGI - Recovering from interrupts with signals mike_lottridge@mentorg.com
Re: CGI - Recovering from interrupts with signals <flavell@mail.cern.ch>
Re: CGI - Recovering from interrupts with signals <lr@hpl.hp.com>
CGI won't return text field info?? sleepernyc@my-deja.com
Re: CGI won't return text field info?? <AgitatorsBand@yahoo.com>
Re: CGI, netBIOS, nbtstat <clawson@micron.net>
CGI.pm, was Re: Attn: Perl/CGI wizards. Your expertis (William Burrow)
CGI_Lite Mime Types and MAC <webresearch@indy-soft.com>
Re: Changing attribs of a file on server, how? <nikita@mondenet.com>
Re: changing password in perl (chpasswd) <dchrist@dnai.com>
Charter <msalter@bestweb.net>
Re: Charter (Jon Bell)
Circular buffering (Neil Cherry)
Re: Circular buffering (M.J.T. Guy)
Re: Circular buffering (Michel Dalle)
Re: comments form to a page <rootbeer@redcat.com>
comparing text with words (Bjoern Jacke)
Re: comparing text with words <lr@hpl.hp.com>
Re: comparing text with words <aqumsieh@matrox.com>
Re: comparing text with words <lr@hpl.hp.com>
Re: comparing text with words <jtribbeck@argogroup.com>
Comparing Time <nik@cheddarcheese.de>
Re: Comparing Time <sr@pc-plus.de>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 24 Oct 1999 23:00:48 +0200
From: furio ercolessi <furioag@spin.it>
Subject: Cannot assign the null string to a hash element
Message-Id: <38137380.2EBD4E61@spin.it>
I am becoming crazy with this stupid thing. Here is a loop
to strip leading and trailing spaces from strings in a hash:
foreach $key (keys %input) { # go thru a hash
$_ = $input{$key}; # copy into $_
s/^\s*//; # strip leading spaces
s/\s*$//; # strip trailing spaces
print DBG "$key: $_|\n";
$input{$key} = $_; # reassigning it DOES NOT WORK!
print DBG "$key: $input{$key}\|\n";
}
Now I have a KEY such that $input{'KEY'} eq " "
(three spaces). After the s operators , $_ contains
the null string as it should. But the assignment
does not seem to have any effect, and my $input{'KEY'}
retains the original data!!! That is, the output of the
above is
KEY: |
KEY: |
Replacing the above with the equivalent
foreach $key (keys %input) {
$input{$key} =~ s/^\s*//;
$input{$key} =~ s/\s*$//;
}
also leaves the hash element unchanged. Applying the undef operator
to $input{$key} doesn't work either!
Assigning the null string seems to be a crucial ingredient.
Why is my hash element so resistant to a reassignment?
This is perl, version 5.004_05 built for i386-linux (the perl-5.004m7-1
RPM on
a stock RedHat 5.2 Intel-based system).
Thanks in advance for any clue
furio ercolessi
Spin - Trieste (Italy)
------------------------------
Date: Wed, 27 Oct 1999 11:29:29 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Cannot assign the null string to a hash element
Message-Id: <x3yogdk9606.fsf@tigre.matrox.com>
furio ercolessi <furioag@spin.it> writes:
> I am becoming crazy with this stupid thing. Here is a loop
> to strip leading and trailing spaces from strings in a hash:
>
> foreach $key (keys %input) { # go thru a hash
> $_ = $input{$key}; # copy into $_
> s/^\s*//; # strip leading spaces
> s/\s*$//; # strip trailing spaces
> print DBG "$key: $_|\n";
> $input{$key} = $_; # reassigning it DOES NOT WORK!
> print DBG "$key: $input{$key}\|\n";
> }
>
> Now I have a KEY such that $input{'KEY'} eq " "
> (three spaces). After the s operators , $_ contains
> the null string as it should. But the assignment
> does not seem to have any effect, and my $input{'KEY'}
> retains the original data!!! That is, the output of the
> above is
>
> KEY: |
> KEY: |
What are you talking about?
% perl -w
$input{KEY} = ' ';
foreach $key (keys %input) { # go thru a hash
$_ = $input{$key}; # copy into $_
s/^\s*//; # strip leading spaces
s/\s*$//; # strip trailing spaces
print "$key: $_|\n";
$input{$key} = $_; # reassigning it DOES NOT WORK!
print "$key: $input{$key}\|\n";
}
__END__
KEY: |
KEY: |
As expected. Perhaps you found a bug in your version of Perl.
I would suggest that you try out the minimal example I show above. If
it works fine, then there is something wrong with your program, and
you should look deeper, or post a bigger chunk and someone will try to
help you.
Else, upgrade to the latest version of Perl, and try again.
HTH,
--Ala
------------------------------
Date: Wed, 27 Oct 1999 13:45:23 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Cannot assign the null string to a hash element
Message-Id: <3819017e.1217467@news.skynet.be>
furio ercolessi wrote:
>foreach $key (keys %input) { # go thru a hash
> $_ = $input{$key}; # copy into $_
> s/^\s*//; # strip leading spaces
> s/\s*$//; # strip trailing spaces
> print DBG "$key: $_|\n";
> $input{$key} = $_; # reassigning it DOES NOT WORK!
> print DBG "$key: $input{$key}\|\n";
>}
>
>Now I have a KEY such that $input{'KEY'} eq " "
>(three spaces). After the s operators , $_ contains
>the null string as it should. But the assignment
>does not seem to have any effect, and my $input{'KEY'}
>retains the original data!!!
That's weird. It works for me. Are you sure this is a normal hash, i.e.
not a tied one?
%input = ( a => ' ', b => ' x ');
after running the above snippet, I see:
a: |
a: |
b: x|
b: x|
>foreach $key (keys %input) {
> $input{$key} =~ s/^\s*//;
> $input{$key} =~ s/\s*$//;
>}
>
>also leaves the hash element unchanged.
It works for me.
Maybe try assigning *anything* to the hash elements, and see if it makes
a difference.
Oh, and in order to contribute something useful (;-), here's a shorter
version, still:
#using a hash slice:
foreach (@input{keys %input}) {
s/^\s+//;
s/\s+$//;
}
Unfortunately, the next one doesn't work. Apparently, values() returns
*copies* of the values in the hash:
foreach (values %input) {
# no effect:
s/^\s+//;
s/\s+$//;
}
--
Bart.
------------------------------
Date: Mon, 25 Oct 1999 15:06:10 GMT
From: pinkelma@my-deja.com
Subject: CDONTS and Perl?
Message-Id: <7v1rku$7c0$1@nnrp1.deja.com>
Is there anyway to send mail using CDONTS in a perl script (on NT
Server with IIS 4.0), if so how.
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Oct 1999 05:15:03 GMT
From: mike_lottridge@mentorg.com
Subject: CGI - Recovering from interrupts with signals
Message-Id: <7v61om$8ve$1@nnrp1.deja.com>
Suppose you have a cgi script that reads a file into an array, displays
a form to let a user update a record in the array, then dumps the array
back out to the file. Isn't it possible to have the script interrupted
while it is writing the file back out, resulting in a truncated file?
If this is a real problem, what's the best way to handle it? With a
signal handler (perhaps making a backup of the file before the update,
and restoring the backup in the handler?). But the perl docs seem to
imply that signal handlers can be unreliable if you do more than the
absolute minimum of stuff in them.
I see lots of example cgi scripts that have the read/modify/write
approach, with no apparent attempt to recover from an interrupt when
updating the file. Is this not a potential reliablility issue?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Oct 1999 16:25:39 GMT
From: mike_lottridge@mentorg.com
Subject: Re: CGI - Recovering from interrupts with signals
Message-Id: <7v791t$577$1@nnrp1.deja.com>
In article <MPG.128033c5822878c698a139@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <7v61om$8ve$1@nnrp1.deja.com> on Wed, 27 Oct 1999 05:15:03
> GMT, mike_lottridge@mentorg.com <mike_lottridge@mentorg.com> says...
> > Suppose you have a cgi script that reads a file into an array,
displays
> > a form to let a user update a record in the array, then dumps the
array
> > back out to the file. Isn't it possible to have the script
interrupted
> > while it is writing the file back out, resulting in a truncated
file?
>
> Yes, it is very possible.
>
<<deleted>>
> The best way is described in perlfaq5: "How do I change one line in a
> file/delete a line in a file/insert a line in the middle of a
> file/append to the beginning of a file?"
>
> Write a temporary file, then rename it to the original file. That
>way, there is always a sound copy of the file around, no matter what
>happens.
>
Simple and clean solution! Thanks. Now why doesn't everyone do that??
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Oct 1999 19:10:35 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI - Recovering from interrupts with signals
Message-Id: <Pine.HPP.3.95a.991027190518.14375D-100000@hpplus01.cern.ch>
On Wed, 27 Oct 1999 mike_lottridge@mentorg.com wrote:
> > The best way is described in perlfaq5:
[...]
> > Write a temporary file, then rename it to the original file. That
> >way, there is always a sound copy of the file around, no matter what
> >happens.
> >
>
> Simple and clean solution! Thanks. Now why doesn't everyone do that??
Because unfortunately not everyone has the sense to check the FAQs.
------------------------------
Date: Tue, 26 Oct 1999 22:56:11 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: CGI - Recovering from interrupts with signals
Message-Id: <MPG.128033c5822878c698a139@nntp.hpl.hp.com>
In article <7v61om$8ve$1@nnrp1.deja.com> on Wed, 27 Oct 1999 05:15:03
GMT, mike_lottridge@mentorg.com <mike_lottridge@mentorg.com> says...
> Suppose you have a cgi script that reads a file into an array, displays
> a form to let a user update a record in the array, then dumps the array
> back out to the file. Isn't it possible to have the script interrupted
> while it is writing the file back out, resulting in a truncated file?
Yes, it is very possible.
> If this is a real problem, what's the best way to handle it? With a
> signal handler (perhaps making a backup of the file before the update,
> and restoring the backup in the handler?). But the perl docs seem to
> imply that signal handlers can be unreliable if you do more than the
> absolute minimum of stuff in them.
One way is to ignore interrupts during the writing of the file.
Overkill:
@SIG{keys %SIG} = ('IGNORE') x keys %SIG;
Or selectively on $SIG{INT} etc.
But this is not the best way, because shit can still happen.
> I see lots of example cgi scripts that have the read/modify/write
> approach, with no apparent attempt to recover from an interrupt when
> updating the file. Is this not a potential reliablility issue?
The best way is described in perlfaq5: "How do I change one line in a
file/delete a line in a file/insert a line in the middle of a
file/append to the beginning of a file?"
Write a temporary file, then rename it to the original file. That way,
there is always a sound copy of the file around, no matter what happens.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 26 Oct 1999 19:09:28 GMT
From: sleepernyc@my-deja.com
Subject: CGI won't return text field info??
Message-Id: <7v4u95$fn8$1@nnrp1.deja.com>
I've got a fairly tight survey form on my sight , but can't seem to
make my Comments: field to return text to my form.log
Any ideas?
I'm using
If you have any other comments or suggestions for us, please feel free
to enter them here:<BR>
<textarea name="textfield" row="4" cols="50">Comments:</textarea>
and in my data_order = (name,address,submit_by,textfield)
etc.
Many TIA!!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 26 Oct 1999 20:58:38 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: CGI won't return text field info??
Message-Id: <2CoR3.1630$LR3.287723@news.shore.net>
sleepernyc@my-deja.com wrote:
: and in my data_order = (name,address,submit_by,textfield)
We'll need a little more code than that to know what's going on in your
program.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Wed, 27 Oct 1999 12:57:52 -0700
From: Chris Lawson <clawson@micron.net>
Subject: Re: CGI, netBIOS, nbtstat
Message-Id: <38175940.8A55C8AA@micron.net>
If you're running on a Win32 machine, try running the nbtstat
command and parsing the output:
$_ = qx/"nbtstat -A $IP[$i]"/;
if ( m/Host not found/) {$Name[$i] = "Unknown";
$User[$i] = "Non-MS";}
else { $Name[$i] = ($_ =~ /(\S*)\s*<00>/)[0];
$User[$i] = ($_ =~ /(\S*)\s*<03>/g)[m/(\S*)\s*<03>/g -1];}
}
------------------------------
Date: 25 Oct 1999 17:28:58 GMT
From: aa126@DELETE.fan.nb.ca (William Burrow)
Subject: CGI.pm, was Re: Attn: Perl/CGI wizards. Your expertise is needed. Simple Question?
Message-Id: <slrn8194qq.gu9.aa126@fan1.fan.nb.ca>
On Fri, 22 Oct 1999 01:27:04 -0400,
bob <bob> wrote:
>file (their logo) through the web browser and save it to the local
>server. I could then have the script print the image link into the
>web page to pull it up, no prob. I would rather access the file
>locally rather that remotely via a simple url. Problem is I can't
>figure out how to SAVE the binary file onto the local server. Did it
>with the form output for the html no sweat all text. I found a small
>script at:
Pick up the CGI perl module at CPAN. It takes care of everything, easy.
The filename parameter you get back is a reference to the file, just
copy the file as indicated in the CGI.pm manpage.
--
William Burrow -- New Brunswick, Canada o
Copyright 1999 William Burrow ~ /\
~ ()>()
------------------------------
Date: Wed, 27 Oct 1999 22:44:29 GMT
From: "Web Research" <webresearch@indy-soft.com>
Subject: CGI_Lite Mime Types and MAC
Message-Id: <hfLR3.87$Ur4.4212@news.rdc1.tn.home.com>
I'm a little confused about the usage of add-mime-type and remove-mime-type
in CGI_Lite.pm
With no modification of the standard properties of CGI_Lite, we are able to
perform uploads of GIF and JPG images with no problems on a PC. Uploaded
images on a MAC are somehow becoming corrupt by the time they are saved on
the UNIX machine.
We don't have direct access to a MAC so this has proven to be a real
back-and-forth chore to test. I think I'm understanding the problem clearly,
but would appreciate some input on my research.
1) Should I be adding 'image/gif' 'image/jpeg' to the mime types, or
removing them? I think remove (see 2).
2) Am I right in understanding that remove-mime-types says "do not futz with
this type of file when you encounter it"?
3) Does the bin hex mac mime type figure in to this or only 'other' binary
MAC files such as applications or SIT stuffits?
Thanks for any insight,
Rusman
------------------------------
Date: Mon, 25 Oct 1999 18:41:33 GMT
From: Nikita Synytskyy <nikita@mondenet.com>
Subject: Re: Changing attribs of a file on server, how?
Message-Id: <3814A467.6F59BF0F@mondenet.com>
David Christensen wrote:
>
>
> Try putting your question on:
>
> comp.infosystems.www.authoring.cgi
Thanks! Got my answers there.
Nikita.
------------------------------
Date: Mon, 25 Oct 1999 21:57:47 -0700
From: "David Christensen" <dchrist@dnai.com>
Subject: Re: changing password in perl (chpasswd)
Message-Id: <7v3d4j$d9h$1@pollux.dnai.com>
Alan & everyone on comp.lang.perl.misc:
>> Try putting your question on:
>>
>> comp.infosystems.www.authoring.cgi
> Relax your CGI trigger finger.
I wasn't trying to flame Amir. I sent the same advice to at least half
a dozen people that day, specifically after reading a bunch of flames
against people with Perl/Cgi questions. I simply wanted to redirect
Amir and the others to a more appropriate (and upbeat, IHMO) forum.
BTW does anybody know if it is possible to have multiple newsgroup names
map into one forum? For example:
comp.lang.perl.cgi => comp.infosystems.www.authoring.cgi
David Christensen
dchrist@dnai.com
------------------------------
Date: Wed, 27 Oct 1999 15:24:56 GMT
From: Mike Salter <msalter@bestweb.net>
Subject: Charter
Message-Id: <Pine.BSF.4.05.9910271114300.20543-100000@monet.bestweb.net>
Last week I asked "Where is the c.l.p.m charter?", to which I received no
response. I did receive e-mail asking me if I had been informed of its
location.
After looking around, I came across the post listed below.
That is all I have been able to locate. Is that about it?
Mike
----
Path: usenet.cis.ufl.edu!usenet.eel.ufl.edu!gatech!howland.reston.ans.net!news.
sprintlink.net!psgrain!nntp.teleport.com!usenet
From: merlyn@stonehenge.com (Randal L. Schwartz)
Newsgroups: comp.lang.perl.announce,comp.lang.perl.misc,comp.lang.perl
Subject: From your moderator: CLP.announce is up and running
Followup-To: comp.lang.perl.misc
Date: 19 May 1995 15:17:51 GMT
Organization: Stonehenge Consulting Services; Portland, Oregon, USA
Lines: 49
Approved: merlyn@stonehenge.com (comp.lang.perl.announce moderator)
Message-ID: <MERLYN.95May19081751@linda.teleport.com>
Reply-To: merlyn@stonehenge.com
NNTP-Posting-Host: linda.teleport.com
Xref: usenet.cis.ufl.edu comp.lang.perl.announce:11 comp.lang.perl.misc:94 comp
.lang.perl:50117
As you can see, postings for comp.lang.perl.announce are beginning to
flow.
When you post an article, you should get a reply from my perl response
daemon (actually, a complex maze of procmail, mailagent, Perl, MH, and
various other tools) nearly immediately if you are on the Internet.
(If you're off in the store-and-forward world... it'll still show up,
but later.) If you *don't* get a response from my daemon in a
reasonable amount of time, feel free to write me directly so I can
help diagnose the problem.
I'll try to process the queue every seventy-two hours or better.
You'll get email from me (for now) the moment I either accept or
reject the article in accordance with the charter (see below).
By the way, posting is handled via Rodger Anderson's excellent
NNTPClient Perl module -- thanks to him for letting me work with it a
bit to do my postings.
The comp.lang.perl newsgroup is supposed to be going away soon (the
timeline escapes me), so start posting to and reading
comp.lang.perl.misc. Expect further announcements as rmgroup-day
approaches.
Oh yeah... the official announcement looked like this:
CHARTERS
A split of comp.lang.perl into comp.lang.perl.misc and
comp.lang.perl.announce is proposed. Existing traffic in
comp.lang.perl will migrate to comp.lang.perl.misc, which will
remain an unmoderated newsgroup for discussion of issues of
all sorts relating to perl.
comp.lang.perl.announce will be a low-volume, moderated group
for announcements of new releases of perl or its extensions
(oraperl, sybperl, etc.) and periodic postings related to
perl. It will be moderated from the address
<clpa@perl.com>. Actual moderation will be carried out by
Randal Schwartz <merlyn@stonehenge.com>, with Bart Robinson
<lomew@cs.utah.edu> and Robert Haas
<rhaas@cygnus.arc.nasa.gov> as backup moderators.
Just another Perl newsgroup moderator,
--
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@ora.com)
Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
------------------------------
Date: Wed, 27 Oct 1999 16:26:21 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Charter
Message-Id: <FK9sBx.F6u@presby.edu>
Mike Salter <msalter@bestweb.net> wrote:
>Last week I asked "Where is the c.l.p.m charter?", to which I received no
>response.
Look at ftp://ftp.isc.org/pub/usenet/news.announce.newgroups/
and you will find the original RFDs, CFV and vote results postings.
They're probably filed under something like comp.lang.perl-reorg.
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
[ Information about newsgroups for beginners: ]
[ http://www.geocities.com/ResearchTriangle/Lab/6882/ ]
------------------------------
Date: Tue, 26 Oct 1999 14:08:54 GMT
From: njc@dmc.uucp (Neil Cherry)
Subject: Circular buffering
Message-Id: <slrn81bddi.36g.njc@dmc.uucp>
I'm interested in using circular buffering in my Perl program. Does
anyone have code examples of how to accomplish this?
--
Linux Home Automation Neil Cherry ncherry@home.net
http://members.home.net/ncherry (Text only)
http://meltingpot.fortunecity.com/lightsey/52 (Graphics GB)
------------------------------
Date: 27 Oct 1999 17:37:35 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Circular buffering
Message-Id: <7v7d8v$ifb$1@pegasus.csx.cam.ac.uk>
In article <slrn81bddi.36g.njc@dmc.uucp>, Neil Cherry <ncherry@home.net> wrote:
>I'm interested in using circular buffering in my Perl program. Does
>anyone have code examples of how to accomplish this?
Use an array, say @buff, to hold the buffer.
Then push @buff, $item; # add $item to @buff
my $item = shift @buff # take $item from @buff
Contrary to what you might guess, these are efficient operations even
if the buffer gets large ( O(1) most of the time ), as Perl is careful
to avoid unnecessary shifting or copying of arrays.
Mike Guy
------------------------------
Date: Tue, 26 Oct 1999 17:07:12 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Circular buffering
Message-Id: <7v4ne4$n9v$1@news.mch.sbs.de>
In article <slrn81bddi.36g.njc@dmc.uucp>, ncherry@home.net wrote:
>I'm interested in using circular buffering in my Perl program. Does
>anyone have code examples of how to accomplish this?
>
You mean like using push, pop, shift, unshift, resetting $#array, slicing
etc. ? I would imagine that reading the documentation would already
help you a lot. Have you tried 'perldoc -f push' and 'perldoc -f shift' ?
Or did you mean something else with circular buffering ?
Michel.
------------------------------
Date: Mon, 25 Oct 1999 12:46:53 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: comments form to a page
Message-Id: <Pine.GSO.4.10.9910251245530.29843-100000@user2.teleport.com>
On 23 Oct 1999, Max S. wrote:
> Newsgroups: comp.lang.perl.misc
> Subject: comments form to a page
>
> hi, I am new to cgi,
Then you should probably be asking in a newsgroup about CGI programming,
rather than one about Perl.
> I am trying to learn perl...
See the FAQ, which can help you far more than I can.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 25 Oct 1999 08:41:46 GMT
From: maccy2@yahoo.com (Bjoern Jacke)
Subject: comparing text with words
Message-Id: <slrn8185qt.kmc.maccy2@student.physik.uni-dortmund.de>
Hello!
I'm fairly new to perl programming and so I have a small generic question:
I have a wordslist of round about 3500 words (which don't change) and I want
to compare all words of a text with each of the words. If one of the words
appears I wanna do something with it. What would be the best way to do this?
Should I put the 3500 words in a hash of lists or what would be a better way
to do it?
Thanks in advance,
Björn
--
Bj"orn Jacke · email: bjoern.jacke@gmx.de
PGP fingerprint RSA: BC 64 6A AC E5 55 BC 4A BA D9 BD 75 50 F1 E0 5D
DSS: 7A26 F4A0 DA1C 22B5 906A C7B8 768A 34B3 E848 7A39
------------------------------
Date: Tue, 26 Oct 1999 14:13:41 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: comparing text with words
Message-Id: <MPG.127fb95d157761ed98a131@nntp.hpl.hp.com>
In article <x3yzox6829g.fsf@tigre.matrox.com> on Tue, 26 Oct 1999
13:23:24 -0400, Ala Qumsieh <aqumsieh@matrox.com> says...
...
+ regexp too big at - line xx.
+
+ when my array had a few thousand elements.
+
+ perldiag explains the following:
+
+ regexp too big
+ (F) The current implementation of regular expressions
+ uses shorts as address offsets within a string.
+ Unfortunately this means that if the regular expression
+ compiles to longer than 32767, it'll blow up. Usually
+ when you want a regular expression this big, there is a
+ better way to do it with multiple statements. See the
+ perlre manpage.
+
+ I looked at the perlre manpage but couldn't figure out what the
+ "better way" was (anybody knows?).
Yes, match multiple statements, which is exactly what you did in your
eval'ed subroutine.
+ So, my solution was to create an anonymous subroutine on the fly. I
+ constructed the subroutine as a long string of the form:
+
+ my $string = "sub {
+ my \$x = shift;
+
+ if (\$x =~ /$pat1/o) { return 1 }
+ if (\$x =~ /$pat2/o) { return 1 }
+ ....
+ ....
+ if (\$x =~ /$patn/o) { return 1 }
+
+ return 0;
+ }";
+
+ where the $pat1 .. $patn are the regexps which are the elements of the
+ initial array.
The following snippet uses the same method, but has a *much* lower golf
score:
my $string = 'sub { local $_ = shift;' .
join('||' => map "/$_/o" => @pats) . '}';
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 26 Oct 1999 13:23:24 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: comparing text with words
Message-Id: <x3yzox6829g.fsf@tigre.matrox.com>
Larry Rosler <lr@hpl.hp.com> writes:
> In article <38143EC9.827F6A89@argogroup.com> on Mon, 25 Oct 1999
> 12:28:09 +0100, Jason P Tribbeck <jtribbeck@argogroup.com> says...
> >
> > If you have an array of your words (@words), then you could create a
> > large regex:
> >
> > my $search = join("|", @words);
>
> This advice is so phenomenally bad that I hate to quote this line, let
> alone the rest of your post.
>
> Not surprisingly, perhaps, this Question has been Asked before, quite
> Frequently in fact. So guess where the answer is?
>
> perlfaq4: "How can I tell whether a list or array contains a certain
> element?"
I recently ran across a similar problem. I have a huge hash (of about
600,000+ elements) and I have an array of regexps. I want to extract
all the hash elements that DO NOT match any of the regexps.
This is the approach I used in case anybody is interested. Comments
are welcome.
Initially, I took the brute force approach, and created a single
regexp like so:
my $exclude = join '|' => @array;
Then, I simply iterated through the keys of the hash, and checked for
a match:
for my $key (keys %hash) {
next if $key =~ /$exclude/o;
...
}
This worked fine for some time. But then I hit an unexpected wall. I
got the following run-time error:
regexp too big at - line xx.
when my array had a few thousand elements.
perldiag explains the following:
regexp too big
(F) The current implementation of regular expressions
uses shorts as address offsets within a string.
Unfortunately this means that if the regular expression
compiles to longer than 32767, it'll blow up. Usually
when you want a regular expression this big, there is a
better way to do it with multiple statements. See the
perlre manpage.
I looked at the perlre manpage but couldn't figure out what the
"better way" was (anybody knows?).
So, my solution was to create an anonymous subroutine on the fly. I
constructed the subroutine as a long string of the form:
my $string = "sub {
my \$x = shift;
if (\$x =~ /$pat1/o) { return 1 }
if (\$x =~ /$pat2/o) { return 1 }
....
....
if (\$x =~ /$patn/o) { return 1 }
return 0;
}";
where the $pat1 .. $patn are the regexps which are the elements of the
initial array. Then I eval()ed this string to get my anonymous
subroutine:
my $does_match = eval $string;
Now, I used this subroutine ref to check for matches:
for my $key (keys %hash) {
next if $does_match->($key);
...
}
This approach worked beautifully. It also gave me a 5-6x gain in
speed.
Hope this helps someone :-)
--Ala
------------------------------
Date: Mon, 25 Oct 1999 10:32:09 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: comparing text with words
Message-Id: <MPG.127e33f01bf09ea398a120@nntp.hpl.hp.com>
In article <38143EC9.827F6A89@argogroup.com> on Mon, 25 Oct 1999
12:28:09 +0100, Jason P Tribbeck <jtribbeck@argogroup.com> says...
> Bjoern Jacke wrote:
> > I have a wordslist of round about 3500 words (which don't change) and I want
> > to compare all words of a text with each of the words. If one of the words
> > appears I wanna do something with it. What would be the best way to do this?
> > Should I put the 3500 words in a hash of lists or what would be a better way
> > to do it?
>
> If you have an array of your words (@words), then you could create a
> large regex:
>
> my $search = join("|", @words);
This advice is so phenomenally bad that I hate to quote this line, let
alone the rest of your post.
Not surprisingly, perhaps, this Question has been Asked before, quite
Frequently in fact. So guess where the answer is?
perlfaq4: "How can I tell whether a list or array contains a certain
element?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 25 Oct 1999 12:28:09 +0100
From: Jason P Tribbeck <jtribbeck@argogroup.com>
Subject: Re: comparing text with words
Message-Id: <38143EC9.827F6A89@argogroup.com>
Bjoern Jacke wrote:
>
> Hello!
>
> I'm fairly new to perl programming and so I have a small generic question:
>
> I have a wordslist of round about 3500 words (which don't change) and I want
> to compare all words of a text with each of the words. If one of the words
> appears I wanna do something with it. What would be the best way to do this?
> Should I put the 3500 words in a hash of lists or what would be a better way
> to do it?
If you have an array of your words (@words), then you could create a
large regex:
my $search = join("|", @words);
Then, if you want to count your words, you could use:
my $count = 0;
while($text =~ /$search/gos ) {
$count++;
}
print "$count words matched\n";
If you want to replace them with 'foo', then use:
$text =~s/$search/foo/gs;
Of course, this will also match substrings of words, but the general
principal is there.
--
Jason Tribbeck Argo Interactive ltd
Senior Design Engineer 7 Dukes Court, Chichester
West Sussex, PO19 2FX
Tel: +44 1243 815 815 Fax: +44 1243 815 805 England
------------------------------
Date: Wed, 27 Oct 1999 13:56:38 +0200
From: Nik Gare <nik@cheddarcheese.de>
Subject: Comparing Time
Message-Id: <49578c3842nik@pop.onlinehome.de>
Hi,
I have a script in which I would like to only display some data if is less
than about 1 month old. The data contains the day, month and year as separate
entities, ie $day, $month, $year.
The script (so far) contains
$now = time;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
So, how would I go about converting the dates in the datafile ($day,
$month,$year) into a form which is comparible with $now?
Thanks in advance,
Nik
------------------------------
Date: Wed, 27 Oct 1999 16:03:36 +0200
From: Stephen Riehm <sr@pc-plus.de>
Subject: Re: Comparing Time
Message-Id: <MPG.1281249f5a330d76989686@news>
nik@cheddarcheese.de said...
> So, how would I go about converting the dates in the datafile ($day,
> $month,$year) into a form which is comparible with $now?
try Time::Local
Steve
------------------------------
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 1175
**************************************