[13195] in Perl-Users-Digest
Perl-Users Digest, Issue: 605 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 20 18:07:14 1999
Date: Fri, 20 Aug 1999 15:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 20 Aug 1999 Volume: 9 Number: 605
Today's topics:
Re: Attn: CRAP (was Re: voting system pealse advise) (Neko)
Creating a perl extension. <kangas@anlon.com>
Debugging the interpreter <bruno@hpesbpm.fc.hp.com>
Re: Debugging the interpreter (Ilya Zakharevich)
Re: Directory Size <heather.wiley.fake@bentley.com>
Re: Find a substring of mixed type but NOT WhiteSpace? <cassell@mail.cor.epa.gov>
Finding the last occurance of a match/reg exp marcza@my-deja.com
Re: Finding URLs <cassell@mail.cor.epa.gov>
Help with CGI::$ENV (Jason W. Storer)
Help with variables in a for loop with varaibles (Adam Berns)
Re: Help with variables in a for loop with varaibles <makkulka@cisco.com>
Re: How Perl handles time <cassell@mail.cor.epa.gov>
Maintaining User Sessions without Cookies <purchase9@hotmail.com>
Re: Maintaining User Sessions without Cookies (Benjamin Franz)
Re: merging complex hashes? <aqumsieh@matrox.com>
New at Perl..Need guidance (Steve Kucera)
Re: new to perl and a bit stupid <aqumsieh@matrox.com>
Perl script for sending email on NT <mzchen@bellatlantic.net>
Re: Perl script for sending email on NT <purchase9@hotmail.com>
Re: processing html on the fly part 2 <flavell@mail.cern.ch>
recovering the query string while using CGI.pm gmahler@my-deja.com
Re: recovering the query string while using CGI.pm <makkulka@cisco.com>
Re: recovering the query string while using CGI.pm <ptimmins@itd.sterling.com>
Recursing through directory headache unibrow@my-deja.com
Regular expression question <pkirlin@my-deja.com>
Re: Regular expression question <sariq@texas.net>
Regular Expression woes (Bill Moseley)
Re: replacing @, /, . etc, in POST method <cassell@mail.cor.epa.gov>
Resursive renaming unibrow@my-deja.com
Re: search script <cassell@mail.cor.epa.gov>
Shell vs Perl kcounts@my-deja.com
Re: Skipping . and .. with readdir (Neko)
Re: Sort Files by Date and then Name <mcking@cajunbro.com>
Re: Sort Files by Date and then Name <vmurphy@gamora.ndhm.gtegsc.com>
Re: Sort Files by Date and then Name (Bill Moseley)
Strange error - with a twist <habfan2@my-deja.com>
The real reason people don't use CGI.pm (Alan Curry)
Re: What are valid characters in hash keys <mcking@cajunbro.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Aug 1999 21:57:11 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Attn: CRAP (was Re: voting system pealse advise)
Message-Id: <7pkivn$32p$1@216.39.141.200>
On 20 Aug 1999 08:08:55 GMT, sholden@pgrad.cs.usyd.edu.au (Sam Holden) wrote:
>On Fri, 20 Aug 1999 00:49:36 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
>>In article <x7pv0jv3e5.fsf@home.sysarch.com> on 19 Aug 1999 17:58:42 -
>>0400, Uri Guttman <uri@sysarch.com> says...
>>> >>>>> "c" == collinf <collinf@moscow.com> writes:
>>...
>>> c> Could you explain what a 'dispatch hash' is?
><snip>
>>
>>Don't need any variables, and don't need any single-quotes. Score a
>>birdie for me! :-)
>>
>> ({
>> add_topic => \&add_topic,
>> showvote => \&showvote,
>> others => \&others,
>> vote => \&vote,
>> results => \&results,
>> delete => \&delete,
>> }->{$FORM{action})->();
>
>eval "&$FORM{action}()";
>
>Why use a hash when you have got the symbol table I say ;)
Or if the prospect of running unknown code through eval() scares you:
$FORM{action}->();
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: Fri, 20 Aug 1999 15:13:38 -0500
From: Kangas <kangas@anlon.com>
Subject: Creating a perl extension.
Message-Id: <37BDB6F2.BC6917BE@anlon.com>
Where is the best place for some documentation on creating a perl
extension. I don't care if all it does is print 'Hello, World.'. I just
want to try it.
Thanks for any and all input.
--
Michael Kangas
kangas@anlon.com
------------------------------
Date: 20 Aug 1999 20:07:31 GMT
From: Bruno Melli <bruno@hpesbpm.fc.hp.com>
Subject: Debugging the interpreter
Message-Id: <7pkci3$lm2$1@fcnews.fc.hp.com>
My version of Perl (5.004) dies when trying to clean stuff up after
executing a script. The loop in visit() ends up traversing through
objects that are obviously garbage. The refcount of an SV object looks
like a pointer address and since this is used to walk an array you
endup in lala land.
Is there a "well known" way to corrupt the sv_arena
(what's an SV anyway, symbol value ?) from a perl script ?
Anybody can give me a pointer on how to debug such a bear ?
The perl script itself is quite involved (it uses C++ libraries through
SWIG generated bindings) and I haven't had much luck reducing it. Adding
or removing lines of code or even modules just seem to hide the problem.
thanks,
bruno.
------------------------------
Date: 20 Aug 1999 21:47:30 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Debugging the interpreter
Message-Id: <7pkidi$bjs$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Bruno Melli
<bruno@hpesbpm.fc.hp.com>],
who wrote in article <7pkci3$lm2$1@fcnews.fc.hp.com>:
> My version of Perl (5.004) dies when trying to clean stuff up after
> executing a script. The loop in visit() ends up traversing through
> objects that are obviously garbage. The refcount of an SV object looks
> like a pointer address and since this is used to walk an array you
> endup in lala land.
>
> Is there a "well known" way to corrupt the sv_arena
> (what's an SV anyway, symbol value ?) from a perl script ?
Sure. Any refcounting problem will.
> Anybody can give me a pointer on how to debug such a bear ?
> The perl script itself is quite involved (it uses C++ libraries through
> SWIG generated bindings) and I haven't had much luck reducing it. Adding
> or removing lines of code or even modules just seem to hide the problem.
Of course, you want to check 5.005_03 first. If it does not help,
most probably it is a SWIG problem. Then good luck, I know no
third-parties who understand how SWIG works.
Ilya
------------------------------
Date: Fri, 20 Aug 1999 17:24:39 -0400
From: Heather Wiley <heather.wiley.fake@bentley.com>
To: Per Kistler <kistler@fnmail.com>
Subject: Re: Directory Size
Message-Id: <37BDC797.4E4B848@bentley.com>
if all you want is size, wouldn't "-s filename" be quicker than fstat?
Per Kistler wrote:
> Hi Gary
>
> If it's on unix one may just use the unix command "du -ks <dir>"
> and process the output with perl.
> One could do it more perlish with File::Recurse and fstat
> to get the size of each file...
>
> -Per.
>
> Gary Segler wrote:
>
> > Could anyone point me to a faq or Module that can tell me how to get
> > the size of a directory? I would like to scan a volume of home
> > directories that holds mail stores. My goal is to find out the size
> > of the mail store directory for every user.
>
> --
> Per Kistler kistler@fnmail.com / kistler@gmx.net
> ------------------------------------------------------------
------------------------------
Date: Fri, 20 Aug 1999 13:15:41 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Find a substring of mixed type but NOT WhiteSpace?
Message-Id: <37BDB76D.44C00292@mail.cor.epa.gov>
poocus@my-deja.com wrote:
>
> In article <37BD4FF3.E3EBB373@home.com>,
> Paul Dobbs <pdobbs@home.com> wrote:
[snip of unneeded part]
> > To grab a substring of just alphanumeric items which are 80
> > characters or longer
> > and NO whitespace, I can find that with $text =~
> > m%(\w{80,})%;
> >
> > But how do I pick out a substring of mixed character types
> > (letter, number and
> > symbol but not whitespace) that are >=80 characters long?
[ditto]
> I'm new to perl myself so don't take this as gospel, but have you tried
> this:
> $text =~
> > m%(\w{0,80})%;
>
> this will look for lines with 0 to 80 characters in length.
Umm, did you check this on some trial cases? It is really
important in a group like this to make sure your answers are
as helpful as possible.
First, \w won't find any symbols. \w matches letters, numbers,
and the underscore only. \s matches whitespace, and hence
\S matches non-whitespace characters.
Second, this won't look for "lines with 0 to 80 characters
in length" as you put it. This could cause a misunderstanding.
m/(\S{0,80})/ could match a substring of up to 80 characters
in a line of arbitrary length. To make sure the *line* is
0 to 80 characters wide, you need to make sure you match the
whole line using ^ and $ .
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 20 Aug 1999 21:27:53 GMT
From: marcza@my-deja.com
Subject: Finding the last occurance of a match/reg exp
Message-Id: <7pkh8b$egu$1@nnrp1.deja.com>
O.k. I can find the last occurance of a match by using a loop
similar to:
$string = "One table two table three table forth table";
while ($string =~ /(\w+)\s+table\b/g) {
}
But can find the word directly before the last occurnace of a
match without a loop - just with a reg expression ?
Bye
Marcus
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 13:26:31 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Finding URLs
Message-Id: <37BDB9F7.34D5A4A6@mail.cor.epa.gov>
Samay wrote:
>
> Hi,
> I am looking for search engine or program, which can give
> me all the URLs with searching with regex..
> ex..
> I want all the url that says http://*/sports or
> http://*.*sports*.com/
The way regexes work is to study possible matches against
a specified string. Going the other way isn't possible.
You can't list all the valid URLs which *might* match
either of your examples.
> How I should start?
> and How I can proceed?
Get a list of all the URLs you can access. Then use
regexes to see which of them match.
And when you do this, be sure to use legal regexes. Your
first regex would match:
http:///////////////sports
http://sports
but none of the URLS you wanted. And your second
would match:
http:/notenoughslashestostart$$sportXcom/
which isn't what you wanted either.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 20 Aug 1999 21:44:21 GMT
From: jstorer@elk.uvm.edu (Jason W. Storer)
Subject: Help with CGI::$ENV
Message-Id: <7pki7l$1r5ij$1@swen.emba.uvm.edu>
Does anyone know an online resource to find all the uses of the $ENV hash?
All I know right now is how to get the url parameters (?...&...)? Thanks!
-Jason
------------------------------
Date: Fri, 20 Aug 1999 21:04:58 GMT
From: adam@adamb.com (Adam Berns)
Subject: Help with variables in a for loop with varaibles
Message-Id: <rrrgnqegmkf30@corp.supernews.com>
What I have is a for loop that looks like this:
for ($temp=1; $temp <= $nofields; $temp++) {
if ($FORM{'eventid.$temp.guest'} ne "") {
$FORM{'eventid.$temp.guest'}++;
$FORM{eventid.$temp.cost} = $FORM{eventid.$temp.cost} *
$FORM{'eventid.$temp.guest'};
$FORM{'eventid.$temp.guest'}--;
}
}
What I want to happen is thsy yhr $temp is replaced by a number. SO that when
ran, I would get something like this:
for ($temp=1; $temp <= $nofields; $temp++) {
if ($FORM{'eventid1guest'} ne "") {
$FORM{'eventid1guest'}++;
$FORM{eventid1cost} = $FORM{eventid1cost} *
$FORM{'eventid1guest'};
$FORM{'eventid.$temp.guest'}--;
}
}
Thanks!
------------------------------
Date: Fri, 20 Aug 1999 14:55:04 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Help with variables in a for loop with varaibles
Message-Id: <37BDCEB8.2BA2CCE@cisco.com>
[ Adam Berns wrote:
> What I have is a for loop that looks like this:
> for ($temp=1; $temp <= $nofields; $temp++) {
> if ($FORM{'eventid.$temp.guest'} ne "") {
> $FORM{'eventid.$temp.guest'}++;
> $FORM{eventid.$temp.cost} = $FORM{eventid.$temp.cost} *
> $FORM{'eventid.$temp.guest'};
> $FORM{'eventid.$temp.guest'}--;
> }
> }
>
> What I want to happen is thsy yhr $temp is replaced by a number. SO that when
> ran, I would get something like this:
The following statement $FORM{'eventid.$temp.guest'}++; ends up
creating a new key in the hash %FORM. The correct way to do this
is $FORM{'eventid'.$temp.'guest'}++ so that value for $temp is substituted.
See the example below.
--
use Data::Dumper;
$temp =1;
$FORM{'eventid'.$temp.'guest'} = 1 ;
print Dumper \%FORM ;
$FORM{'eventid'.$temp.'guest'} +=1 ;
print Dumper \%FORM ;
$FORM{'eventid.$temp.guest'} +=1 ;
print Dumper \%FORM ;
--results --
$VAR1 = {
'eventid1guest' => 1
};
$VAR1 = {
'eventid1guest' => 2
};
$VAR1 = {
'eventid1guest' => 2,
'eventid.$temp.guest' => 1
};
~
-- Makarand
------------------------------
Date: Fri, 20 Aug 1999 13:39:46 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How Perl handles time
Message-Id: <37BDBD12.1054A39B@mail.cor.epa.gov>
steveeq1@earthlink.net wrote:
>
> I know how to break down a moment time into variables with Perl:
>
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
Actually, the 'time' value is the default there. And you
can pick out just a slice if you want.. which is really what
most people have in mind.
> Simple stuff. However, does anyone know how to do the opposite? That
> is, take a date (Say, "03/01/99) and convert it to the long integer
> (935175372)?
Umm, did you look in the FAQ? Because this is a Frequently
Asked Question. You can use perldoc like this at a command
line:
perldoc -q dates
and find the answer to this question:
"How can I compare two dates and find the difference?"
> Reason I need to do this is because I need to compare dates in perl and
> comparing the long integers seems to be the best way to do it.
Yes, it probably is. Perl has a number of modules which
can help you here. Most of them are in the Date:: hierarchy
on CPAN.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 20 Aug 1999 17:28:07 -0400
From: "SH" <purchase9@hotmail.com>
Subject: Maintaining User Sessions without Cookies
Message-Id: <37bdc6b1@news1.us.ibm.net>
Is there anyway in Perl to remember a specific users preferences even after
they close their browser (without any client side involvement)? Basically a
shopping cart that saved information over a period of time. If you could
give me a push in the right direction I would be very grateful.
stirling@scalarsplit.com
------------------------------
Date: Fri, 20 Aug 1999 21:32:02 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: Maintaining User Sessions without Cookies
Message-Id: <mPjv3.126$4D2.19711@typhoon01.swbell.net>
In article <37bdc6b1@news1.us.ibm.net>, SH <purchase9@hotmail.com> wrote:
>Is there anyway in Perl to remember a specific users preferences even after
>they close their browser (without any client side involvement)? Basically a
>shopping cart that saved information over a period of time. If you could
>give me a push in the right direction I would be very grateful.
With the restriction postulated (no client side involvement),
no - there is no way to achieve state persistence after they exit
their browser.
--
Benjamin Franz
------------------------------
Date: Fri, 20 Aug 1999 13:54:45 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: merging complex hashes?
Message-Id: <x3yhflucp7e.fsf@tigre.matrox.com>
Stephen Riehm <sr@pc-plus.de> writes:
> I have the sick desire to merge two complex hashes - more to the point,
> I have
> objects which contain objects which contain...., and when changes are
> made, I
> want to add those changes to the existing objects, without killing the
> other
> information.
I would urge you to have a look at perlfaq4:
How do I print out or copy a recursive data structure?
I think it might help you find what you're looking for.
HTH,
Ala
------------------------------
Date: 20 Aug 1999 13:54:23 -0700
From: stevek@sonic.net (Steve Kucera)
Subject: New at Perl..Need guidance
Message-Id: <7pkf9v$317@bolt.sonic.net>
I am starting to write my own Perl scripts and could use a little guidance.
Here is the problem we are trying to solve. We have a lousy inventory system
at work and have relied on a sheet of paper that shows the available product
along with the serial number. When the sales rep sells one of the pieces,
they marked the sheet with their initals as well as the order number.
We recently went over to a shared Excel spreadsheet which answers the
problem of having the information available at the desk, but it is extremely
slow to load and can't be opened by more than one person at all. I am
writing a perl script to solve the problem.
So far I have created a form that allows the production department to add
the product by amended a data file, and I have created another form that
allows the sales department to read the data from the data file.
What I need now is a method for the sales department to "tag" a table so the
other sales reps know it is no longer available for sale. Additionally I
will need a way for production to go in and delete the tables that have
shipped and no longer need to appear on the list.
I know how to create the forms and manipulate the variables, as well as
overwrite or amend data files. But I need a little guidance in the best way
to proceed. Should I overwrite one data file or create and read from a
second one? Should I create a hash using the serial number as a key and work
with the data that way?
Any suggestions would be appreciated. Thanks. I am just looking to be
pointed in the right direction. I will work out the specifics on my own.
------------------------------
Date: Fri, 20 Aug 1999 14:09:53 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: new to perl and a bit stupid
Message-Id: <x3yg11ecoi7.fsf@tigre.matrox.com>
ceara_rea@hotmail.com writes:
> this is probably a very dumb question, but I've never used perl before
> and I'm trying to write a script in it.........
Would reading a little bit of Perl's docs help?
I would really think so, especially that you are planning to write a
Perl script.
> I'm trying to extract some data from a file which is split up into
> several sections, I'm only interested in data contained in one
> particular section which has the form:-
>
> SECTION HEADER
> lots of text lines
> that i want to do
> something with
> ^$ (blank line marking end of section)
Good. What is troubling you exactly?
> If I was writing this in awk I'd start at pattern /SECTION HEADER/ and
> use the 'getline' function in a loop to get all the text lines until I
> hit a blankline. Alas sob, sob there's no getline in perl so I'm stuck.
No getline function in Perl?!
Do you really think that Perl (which has become, pretty much, the
standard tool for file manipulation) would come without an equivalent
to awk's getline?
It's not Perl's problem if you can't read the docs.
> I've done a2p and this gives me a subroutine for getline (which
> incidentally when I put it into my script doesn't work) but I'm not sure
> that this is the best way to do it, I have an inkling that maybe I
> should be putting the text lines of this section into an array and then
> reading each $line of the array? but I haven't got a clue how to
> construct it.
Then why not read something about Perl first?
It will be equally hard for me to write a "hello world" program in a
language like Eiffel, because I know nothing about the language. How
do you expect to write a Perl program without knowing much about Perl?
Anyway, I would ask Perl to read the file in "paragraph mode". This
will make life easier.
> I'd greatly appreciate any help, and if somebody could spoon feed me the
> code that would be even better.
That sentence says it all.
> Many thanks
> Ceara
To tell you the truth, I was planning to give you (or spoon feed you)
the source code for what you want. I don't usually tell people to RTFM
without giving them good pointers.
But you don't deserve any.
Ala
PS. With posts like these, I can understand how the regulars react
sometimes.
------------------------------
Date: Fri, 20 Aug 1999 20:15:36 GMT
From: "mc" <mzchen@bellatlantic.net>
Subject: Perl script for sending email on NT
Message-Id: <IHiv3.277$B55.68297@typhoon1.gnilink.net>
Does anyone know how to write Perl script to send email on NT?
on UNIX, it is like:
open(MAIL, "|sendmail......)
Thanks in advance.
mc
------------------------------
Date: Fri, 20 Aug 1999 17:31:48 -0400
From: "SH" <purchase9@hotmail.com>
Subject: Re: Perl script for sending email on NT
Message-Id: <37bdc782@news1.us.ibm.net>
mc <mzchen@bellatlantic.net> wrote in message
news:IHiv3.277$B55.68297@typhoon1.gnilink.net...
> Does anyone know how to write Perl script to send email on NT?
>
> on UNIX, it is like:
> open(MAIL, "|sendmail......)
try sender.pm
> Thanks in advance.
>
> mc
>
>
>
------------------------------
Date: Fri, 20 Aug 1999 22:10:50 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: processing html on the fly part 2
Message-Id: <Pine.HPP.3.95a.990820215102.17601B-100000@hpplus03.cern.ch>
On Fri, 20 Aug 1999, Larry Rosler wrote:
> > > When I run a perl script from my cgi-bin that processes an HTML page
> > > and then spits the page out to the browser, the web browser treats the
^^^^^^^^^^^
> > > cgi-bin as the starting directory to find images and reference all the
> > > paths in the web page.
> >
> > Of course. If you're writing CGI scripts, then this elementary fact
> > should be well known to you.
>
> It's not well known to me. What is well known is that one ought not
> make any assumption about what the current directory is when the CGI
> program starts.
It seems the hon. usenaut is mixing two immiscible concepts. That last
statement of yours is not in dispute, but seems to have no relevance at
all to the browser, nor to the previous discussion, unless I have
seriously misunderstood the questioner's problem.
When the _browser_ retrieves a document from the server, it does it by
means of a URL. That URL defines (by means of its hierarchical
components, separated by "/") a logical hierarchy. It (the browser)
neither knows nor cares which directory of the server's local file
system contains it.
When the resultant document contains relative URLs, the browser resolves
those URLs by reference to the "base URL" of the document which contains
them, and that is the whole issue that seemed to be under discussion in
the previous thread. I.e (using what I think should be self-explanatory
informal terminology) it splits the "file name" part of the base URL
from the "directory" part of the base URL, and uses the "directory" part
to help in resolving the relative URLs. This is the definition of
relative URLs, although I'm using an informal terminology based on the
model of the URL space as a logical "file hierarchy".
> Either the current directory must be set explicitly in
> the program, or all file references should be absolute. Environment
> variables such as $ENV{DOCUMENT_ROOT} or $ENV(PATH_TRANSLATED} may
> faclitate this.
As I was trying to persuade the questioner to think through for himself,
these concepts are purely local to the server, and have no relevance to
the browser (client agent) at all. The WWW works in terms of URLs
(absolute and relative URLs) exchanged across the web interface
(typically HTTP protocol), it isn't interested in what happens inside
the internals of a server.
best regards
------------------------------
Date: Fri, 20 Aug 1999 20:58:26 GMT
From: gmahler@my-deja.com
Subject: recovering the query string while using CGI.pm
Message-Id: <7pkfhc$d7s$1@nnrp1.deja.com>
Brothers and Sisters--
Is there a function in CGI.pm which returns the
query string passed to the perl program? I'm
looking to do this
use CGI(:standard);
$query_string = (function I need to return query string);
#apend new info to old query string
$new_query_string = $query_string."&newinfo=newdata";
#send new query string to another script
Thanks in advance for your help!
Greg Mahler
raegis@hotmail.com
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 14:33:03 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: recovering the query string while using CGI.pm
Message-Id: <37BDC98F.17A1B559@cisco.com>
[ gmahler@my-deja.com wrote:
> Is there a function in CGI.pm which returns the
> query string passed to the perl program? I'm
> looking to do this
> $query_string = (function I need to return query string);
The function you can call is query_string(). This is mentioned in the
part where HTTP session variables are discussed ( in the CGI.pm doc).
You can even use $ENV{'QUERY_STRING'} to get this value.
--
------------------------------
Date: Fri, 20 Aug 1999 21:52:34 GMT
From: Patrick Timmins <ptimmins@itd.sterling.com>
Subject: Re: recovering the query string while using CGI.pm
Message-Id: <7pkimt$fgb$1@nnrp1.deja.com>
In article <7pkfhc$d7s$1@nnrp1.deja.com>,
gmahler@my-deja.com wrote:
> Brothers and Sisters--
>
> Is there a function in CGI.pm which returns the
> query string passed to the perl program? I'm
> looking to do this
>
> use CGI(:standard);
>
> $query_string = (function I need to return query string);
No. This simply can't be done with CGI.pm
I believe Lincoln once said the problem was coming up with a name
for the function that would be intuitive enough to make it useful,
but check the docs ... he explains it there, I think.
and $ENV{'QUERY_STRING'} won't work either, if you're using CGI.pm
... you're just hosed, dude.
Do a POST instead.
Peace.
$monger{Omaha}[0]
Patrick Timmins
ptimmins@itd.sterling.com
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 21:37:50 GMT
From: unibrow@my-deja.com
Subject: Recursing through directory headache
Message-Id: <7pkhrd$ev1$1@nnrp1.deja.com>
Hi there,
I am trying to do a routine which recurses through
a given directory tree at the same time renaming
files. The original routine which I put together
worked just fine on NT, but when I tried it on Solaris
it broke down. Any ideas on a simple method of renaming
files withing a directory tree of unknown depth?
The rename is basically doing a *.txt to *.TXT
I have seen some KSH examples, but would like it
in perl without going to the system.
I recurse just fine, but the renames always fail.
Here is a code snippet:
sub list
{
local($mdir) = @_;
local($mname);
local *MDIR;
unless (opendir(MDIR, $mdir)) {
return;
}
local $_;
foreach $mname (readdir(MDIR)) {
if ($mname eq '.' || $mname eq '..') { print("dots\n");}
else {
if (-f $mdir.'/'.$mname) {
$mname =~ /(.+)\.(.+)/;
if($2 eq "csv") {
unless(rename($mname, $1 . ".CSV")) {
die("Could not rename $1.csv\n");
}
}
if($2 eq "txt") {
unless(rename($mname, $1 . ".TXT")) {
die("Could not rename $1.txt\n");
}
}
}
if (-d $mdir.'/'.$mname) {
&list($mdir.'/'.$mname);
}
}
}
}
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 20:14:07 GMT
From: Phil Kirlin <pkirlin@my-deja.com>
Subject: Regular expression question
Message-Id: <7pkcu4$b3a$1@nnrp1.deja.com>
Does anyone know of a regular expression that will strip out extra
whitespace at the beginning and ends of a string?
EX: " foo bar baz " becomes "foo bar baz"
in other words, take out all the whitespace except the whitespace
between words.
Thanks for any help, please respond by email.
--
Phil Kirlin
pkirlin@softhome.net
http://www.tjhsst.edu/~pkirlin
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 15:38:01 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Regular expression question
Message-Id: <37BDBCA9.B77A2514@texas.net>
Phil Kirlin wrote:
>
> Does anyone know of a regular expression that will strip out extra
> whitespace at the beginning and ends of a string?
Sure, lots of people do.
Of course, they also read the FAQ.
- Tom
------------------------------
Date: Fri, 20 Aug 1999 14:41:53 -0700
From: moseley@best.com (Bill Moseley)
Subject: Regular Expression woes
Message-Id: <MPG.12276b7c3f8d48c39896c6@nntp1.ba.best.com>
Maybe two hours of the dentist drilling on me did some damage. Can
someone help me understand what's going on here?
I'm using the META tags below to pass parameters from a text file into
the program AND to then remove the tags before printing the text.
The example below contains two while() statements. Both work to capture
the data, yet only the first will then go on to delete the tag from $x.
#! perl -w
use strict;
my $x = <<'EOF';
Plain text here
<META NAME="highlight_start" CONTENT="\<em\>">
<META NAME="highlight_end" CONTENT="\</em\>">
remove me
more plain text
removed you
<TITLE>Title Text here</TITLE>
EOF
print "$x\n";
my %hash;
#while ($x =~ /(remove.*) (\w+)/g ) {
while ( $x =~ /<META\s+NAME="(.+?)"\s*CONTENT="(.+?)">/g ) {
$hash{ $1 } = $2;
print $x =~ s/$&//
? "Removed: '$&'\n"
: "Failed to Remove: '$&'\n"
}
print "\n$x\n";
print "$_ => $hash{$_}\n" for keys %hash;
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Fri, 20 Aug 1999 13:20:05 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: replacing @, /, . etc, in POST method
Message-Id: <37BDB875.D27E217E@mail.cor.epa.gov>
Patrick Tully wrote:
>
> Hi,
> I wrote a cgi program that collects some user data, such as email
> address, url and more. The problem is, is that when i get back the
> data, all the @,./ etc. charactore are replaced by %NUMBER. Is there
That's supposed to happen.
> any easy way to replace these %NUMBERS with the original charactors? Am
I would suggest that you look at the URI::Escape module, which
will do this for you. Or read its documentation, and see a way
to do it without using the module.
> i doing something wron? I know i could substitute the charactor back in
> for every single charactor, but i would imagine there is a simpler way?
That's what it comes down to, one way or another. If you look
at CGI scripts on the web, you'll see them do this.. although
many of them do it *wrong*.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 20 Aug 1999 21:24:15 GMT
From: unibrow@my-deja.com
Subject: Resursive renaming
Message-Id: <7pkh1i$e78$1@nnrp1.deja.com>
I have seen many posts regarding
doing single directory file renaming.
My issue is that I cannot seem to
rename files within an entire directory
structure. I can easily recurse through
the directories, but when I go to do
the rename, it fails as .. readdir
only returns a single name, and not a
full path...I think rename fails as it
is trying to rename the file thinking it
is in the current directory..
Any one does this before on Solaris?
Funny thing is the code works on NT....
Best Regards, Don
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 13:31:02 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: search script
Message-Id: <37BDBB06.62409F56@mail.cor.epa.gov>
guys2@mailandnews.com wrote:
>
> Hi Everybody,
Howdy.
> Who can tell me where I can download a free CGI search script or who can
> send me a working one. The script must be capable of searching only the
> directorie(s) given in the script.
Well, first I had better point out that this isn't the right
place to ask for free scripts. The best places for free CGI
scripts are the various repositories on the web. And I hear
that a brand-new newsgroup opened up in the alt.* hierarchy
which might be what you want. It's something like
alt.perlcgi.freelance but I'm not sure. Check what your
news server carries.
If you decide to write this on your own, then this newsgroup
is the right place to get help fixing your code. If you go
this route, then check out the File::Find module [if you want
to look in local directories]; or LWP::Simple or LWP::UserAgent
[if you want to look at web pages].
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 20 Aug 1999 21:24:16 GMT
From: kcounts@my-deja.com
Subject: Shell vs Perl
Message-Id: <7pkh1j$e79$1@nnrp1.deja.com>
Well,
I have a question to so humbly ask of all Perl compatriots.
The system administrator at my workplace doesn't believe
that a Perl program can be written to mimic the functionality of the
below shell script and still keep as simple as the shell script.
!#/usr/bin/ksh
if [ "$1" = "" ]
then sort -t: +2n -3 /etc/passwd
else
grep "[:/]$1[:/]" /etc/passwd | sort -t: +2n -3
fi
He says it took him a page and a half in Perl.
I know it can be more efficient.
Thanks for any input.
K
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 20 Aug 1999 20:26:23 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Skipping . and .. with readdir
Message-Id: <7pkdlf$32p$0@216.39.141.200>
On 20 Aug 1999 16:02:13 GMT, nospam@nospam.nospam (Chris Thompson) wrote:
>In article <37AA1A0A.9561DAD7@home.com>,
>Rick Delaney <rick.delaney@home.com> wrote:
>[...]
>>
>>Tom Phoenix wrote:
>>>
>>> On Thu, 5 Aug 1999, Del Kennedy wrote:
>>>
>>> > next if $next_c =~ /^\.\.?$/; # skip . and ..
>>>
>>> Yes, we all write that. Someday soon, someone who wants to hide files is
>>> going to sneak them into a directory named ".\n" or "..\n" and we'll all
>>> repent! :-)
>>
>>That's why we now have
>>
>> /^\.\.?\z/;
>>
>>which has more style anyway, even if it is a bogey in Perl Golf.
>
>Should be either /^\.\.?\z/s
A bit obscure. I like.
>or /\a\.\.?\z/ , surely?
Too obscure, I guess. I'm sure some shell will let you put alarm bells in
file names, perhaps to warn you whenever you try to open a file you
shouldn't. What you wanted was /\A\.\.?\z/, though you lose some case
symmetry.
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: Fri, 20 Aug 1999 21:09:35 +0000
From: Mark McCoy <mcking@cajunbro.com>
Subject: Re: Sort Files by Date and then Name
Message-Id: <37BDC40F.7FD2BB20@cajunbro.com>
Phillip Armitage wrote:
>
> I'd like to put together a PERL routine which will read the names of
> files in a given subdirectory, and then sort then by name and file
> date. eg. List all the files added to the directory today in
> alphabetical order, then list the files added yesterday in
> alphabetical order, and so on.
>
> My currect code
>
> @files=sort(map(uc($_),grep(m/$FILETYPE$/i,readdir(DIR))));
>
> sorts by uppercase filename. I want to add in the date sorting
> capability
>
> If I were working in DOS I would obtain this kind of listing with the
> command: DIR /O-DN *.*
>
> Anyone know if thiere exists a PERL function which will perform this
> function. Otherwise, any suggestions on where to find or how to write
> (pseudocode) this PERL code?
>
> I'm using Perl for Win32, running on a Windows 95C system
>
> I look forward to your comments and suggestions.
hmm...you have the dos "dir" command and the nice `command` backtic operator.
Do I need to draw a picture?
--
Mark McCoy -- Cajun Brothers Technology, llc
Proud to run Linux since February 1996
This message posted from snowdog, a 100% MS-free machine.
The views in this message do not necessarily reflect the views of my employer
------------------------------
Date: Fri, 20 Aug 1999 21:53:20 GMT
From: Vincent Murphy <vmurphy@gamora.ndhm.gtegsc.com>
Subject: Re: Sort Files by Date and then Name
Message-Id: <xjg7lmqjezz.fsf@gamora.ndhm.gtegsc.com>
>>>>> "Mark" == Mark McCoy <mcking@cajunbro.com> writes:
Mark> Phillip Armitage wrote:
>>
>> I'd like to put together a PERL routine which will read the names of
>> files in a given subdirectory, and then sort then by name and file
>> date. eg. List all the files added to the directory today in
>> alphabetical order, then list the files added yesterday in
>> alphabetical order, and so on.
>>
>> My currect code
>>
>> @files=sort(map(uc($_),grep(m/$FILETYPE$/i,readdir(DIR))));
>>
>> sorts by uppercase filename. I want to add in the date sorting
>> capability
>>
>> If I were working in DOS I would obtain this kind of listing with the
>> command: DIR /O-DN *.*
>>
>> Anyone know if thiere exists a PERL function which will perform this
>> function. Otherwise, any suggestions on where to find or how to write
>> (pseudocode) this PERL code?
>>
>> I'm using Perl for Win32, running on a Windows 95C system
>>
>> I look forward to your comments and suggestions.
Mark> hmm...you have the dos "dir" command and the nice `command`
Mark> backtic operator.
Geez, this won't be too portable though.
opendir( DIR, $dir ) || die "can't open $dir: $\n";
print map { "$_\n" } sort { -M "$dir/$b" cmp -M "$dir/$a" } readdir(DIR);
closedir( DIR );
For the today, yesterday, ... business you may want to consider the
Date::Calc program module. It may have what you need.
--
Vinny
------------------------------
Date: Fri, 20 Aug 1999 14:52:04 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Sort Files by Date and then Name
Message-Id: <MPG.12276ddf31ac4b539896c7@nntp1.ba.best.com>
Phillip Armitage (armitagep@wzmh.com) seems to say...
> sort then by name and file
Someone finally asked a new question!
How do I sort an array by (anything)?
perldoc perlfaq4
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Fri, 20 Aug 1999 20:15:04 GMT
From: Teacher Guy <habfan2@my-deja.com>
Subject: Strange error - with a twist
Message-Id: <7pkcvr$ban$1@nnrp1.deja.com>
I have read previous postings re: Premature end of script headers.
Possible causes: upload binary rather than ascii
file permissions
I have a script that generates text files and places them in a
"datafiles" directory. The same script will read and write data to
files. Files permissions are automatically set at "rw","r","r". If I
need to change file permissions from script , then what is the process?
$mydatadir = "/data1/hypermart.net/dude/datafile/";
$tmpuser = $in{'friend'};
$filext = ".txt";
$fil = $mydatadir.$tmpuser.$filext;
# use concatenation to build path to user's data file
if (-e $fil)
{
#everything is okay. Create lock file.
open (LOCK_FILE2, ">lock.fil");
#open, append record, and close database
open(FILE,">>$fil") || die "Can't find database\n";
print FILE "$in{'date'}|$in{'score'}\n";
close(FILE);
#close lock file
close(LOCK_FILE2);
#delete lock file
unlink("lock.fil");
}
else
{
open (FILE,">$fil");
print FILE "$in{'date'}|$in{'score'}\n";
close (FILE);
}
I'd appreciate any assistance.
Kiley :)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 20 Aug 1999 20:17:42 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: The real reason people don't use CGI.pm
Message-Id: <GJiv3.13237$x04.800574@typ11.nn.bcandid.com>
Mainly, I think it's the documentation.
When viewed in man page format, there are over 9 screenfuls of introductory
information and examples before you get to the first actual description of a
function (the C<new> method). Compare that to the CGI specification at
http://hoohoo.ncsa.uiuc.edu/cgi/. If you were writing your first CGI program,
which would _you_ rather read?
I've always written my own form parsers (one in C, one in perl) just because
it's really quite simple.[1] Split on &, split on =, change + to space, and
change %XX to chr(0xXX). If you _can't_ write your own x-www-form-urlencoded
parser in perl in less time than it would take to read CGI.pm's
documentation, you should probably spend some time studying split() and s///.
Moving on to larger projects, though, the extra features offered by CGI.pm
start to look attractive. I want to make a self-referential state-preserving
form, and CGI.pm was _made_ for those. I want to set and get cookies, and
CGI.pm can do that too! Great!
So I finally had sufficient motivation to read about CGI.pm. The first thing
to read is naturally the description of C<new>. The simplest usage is give
first:
CREATING A NEW QUERY OBJECT (OBJECT-ORIENTED STYLE):
$query = new CGI;
This will parse the input (from both POST and GET methods)
and store it into a perl5 object called $query.
Huh? Where is the error checking? I've been taught to always check my
function calls for failure. That means I expect every library to document the
behavior of its functions when something goes wrong. CGI.pm fails to do that.
For example, suppose $ENV{QUERY_STRING} is malformed... it has an extra & on
the end with no key=value pair after it, or it has a %XX where the X's are
not hex digits... what will C<new> do? Will it return undef and set C<$!>?
Will it die? Should I be doing this inside an eval and if so what should I
look for in $@ afterward?
Up above there was a complete program example
#!/usr/local/bin/perl -w
use CGI; # load CGI routines
$q = new CGI; # create new CGI object
print $q->header, # create the HTTP header
$q->start_html('hello world'), # start the HTML
$q->h1('hello world'), # level 1 header
$q->end_html; # end the HTML
which does not do any error checking at all. I'll therefore guess that the
C<new> method just dies when anything goes wrong.
But I don't like guessing. Guesswork makes bad programs. So I looked at the
code. And what I found was quite sad. Every day someone's getting flamed by
the CGI.pm evangelists for posting CGI code to comp.lang.perl.misc which
doesn't check the return value of
read(STDIN, $query_string, $ENV{CONTENT_LENGTH}). But CGI.pm doesn't check
the return value of that read either.
Here's the read:
sub read_from_client {
...
return read($fh, $$buff, $len, $offset);
}
Its return value is returned to the caller of read_from_client, which throws
it away:
$self->read_from_client(\*STDIN,\$query_string,$content_length,0)
if $content_length > 0;
Generally, error handling in the C<new> method is a mix of die'ing and silent
munging of input. No thought has been give to how the caller is supposed to
detect errors. I'm not impressed. I've done better than CGI.pm, with homemade
form-parsing code that actually checks its input. And I'll probably just do
the same for cookies.[2]
[1] Yes, I know there are many people who have gotten it wrong, and then
published their wrongness. But that doesn't mean it's actually hard to do it
right; just that those people are careless.
[2] By the way, are HTTP cookies described in any RFC? I don't like reading
"specifications" from netscape.com.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: Fri, 20 Aug 1999 20:58:28 +0000
From: Mark McCoy <mcking@cajunbro.com>
Subject: Re: What are valid characters in hash keys
Message-Id: <37BDC174.E4E3132F@cajunbro.com>
Roger Musson wrote:
>
> $hash{key}='some_value';
>
> What are the valid characters for 'key'
>
> I can't find any reference to this anywhere, all examples use
> alphanumeric.
>
> Thanks,
> Roger Musson
I believe it is the same as for the variable names themselves, no
"@$%[]{}<>()..." (unless you want to spend the whole time escaping the reserved
characters)
Stick with alphanumeric and you will be ok.
--
Mark McCoy -- Cajun Brothers Technology, llc
Proud to run Linux since February 1996
This message posted from snowdog, a 100% MS-free machine.
The views in this message do not necessarily reflect the views of my employer
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 605
*************************************