[15604] in Perl-Users-Digest
Perl-Users Digest, Issue: 3017 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 11 14:05:59 2000
Date: Thu, 11 May 2000 11:05:27 -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: <958068326-v9-i3017@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 11 May 2000 Volume: 9 Number: 3017
Today's topics:
Re: #How to parse and strip perl comments? (Abigail)
Re: 'use integer' causes strange output.. (Tad McClellan)
Re: 'use integer' causes strange output.. <rootbeer@redcat.com>
Re: ? How to query secured web-site <rootbeer@redcat.com>
A Simple Question <chris_heaton@mail.com>
a stupid question. <saddek@arch.chalmers.se>
Re: a stupid question. <cure@texas.net>
Re: a stupid question. nobull@mail.com
Re: Auto user creation. <rootbeer@redcat.com>
Re: baby steps with complex hashes of hashes of hashes <bmb@ginger.libs.uga.edu>
Re: Behavior of split seems a bit inconsistent (M.J.T. Guy)
CGI problems (but it IS a perl thing) simeon2000@my-deja.com
Re: CGI problems (but it IS a perl thing) simeon2000@my-deja.com
Re: CGI problems (but it IS a perl thing) <rootbeer@redcat.com>
Re: CGI problems (but it IS a perl thing) nobull@mail.com
Re: cgi scripts and memory allocation <gellyfish@gellyfish.com>
Re: Checking if Child Process is still Alive <jjgreen@cisco.com>
directory contents showing up ?!? <danielxx@bart.nl>
Re: directory contents showing up ?!? <rootbeer@redcat.com>
Re: DIVERTING TO A WEB PAGE <red_orc@my-deja.com>
Re: Faster Access Time to Random Element <jeff@vpservices.com>
Re: Faster Access Time to Random Element (Bart Lateur)
Re: Faster Access Time to Random Element (Randal L. Schwartz)
file upload <germain@greyinteractive.it>
Re: Getting System call return data (Tad McClellan)
Re: Getting System call return data <john.komp@uscorp.net>
Re: Getting System call return data (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 May 2000 17:22:54 GMT
From: abigail@foad.org (Abigail)
Subject: Re: #How to parse and strip perl comments?
Message-Id: <slrn8hlr3c.hsu.abigail@ucan.foad.org>
On 11 May 2000 08:44:58 GMT, Csaba Raduly <csaba_r@my-deja.com> wrote:
++
++ I doubt Homeros caused too many accidents in his time (then again, he
++ was blind :-)
And was has blindness to do with causing many accidents?
Abigail
------------------------------
Date: Thu, 11 May 2000 09:47:53 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: 'use integer' causes strange output..
Message-Id: <slrn8hleg9.k1b.tadmc@magna.metronet.com>
On Thu, 11 May 2000 13:03:55 +0100, Justin Wyllie <justin@comms81.freeserve.co.uk> wrote:
>
>Tom Phoenix <rootbeer@redcat.com> wrote in message
>news:Pine.GSO.4.10.10005101159180.3921-100000@user2.teleport.com...
>> --
>> Tom Phoenix Perl Training and Hacking Esperanto
>> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Please do not waste the resources of tens of thousands of
other people's computers by quoting .sigs
>I had to put ' ' around all my named arguments; eg:
>
>print $q->hidden('-name'=>'hol', '-default'=>'', '-override'=>1);
>
>but this is I think because I have used the -arg approach each time while as
>in your example above your 'value' argument does not have a preceding '-'.
>One day I'll understand what is going on here!
^^^^^^^^^^^^^^^^^^^^^
Reading what the docs that came with your perl say about the
operator that you are using is a Very Good Way of understanding
how the operator works!
perldoc perldata
-----------------
It is often more readable to use the C<< => >> operator between key/value
pairs. The C<< => >> operator is mostly just a more visually distinctive
synonym for a comma, but it also arranges for its left-hand operand to be
interpreted as a string--if it's a bareword that would be a legal identifier.
-----------------
"legal identifier" is described at the top of perldata.pod.
Strings that start with hyphens are _not_ legal identifiers,
so you get no magic quoting. You must do it yourself.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 11 May 2000 09:29:44 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: 'use integer' causes strange output..
Message-Id: <Pine.GSO.4.10.10005110907590.16364-100000@user2.teleport.com>
On Thu, 11 May 2000, Tad McClellan wrote:
> perldoc perldata
>
> -----------------
> It is often more readable to use the C<< => >> operator between key/value
> pairs. The C<< => >> operator is mostly just a more visually distinctive
> synonym for a comma, but it also arranges for its left-hand operand to be
> interpreted as a string--if it's a bareword that would be a legal identifier.
> -----------------
>
> "legal identifier" is described at the top of perldata.pod.
>
> Strings that start with hyphens are _not_ legal identifiers,
> so you get no magic quoting. You must do it yourself.
Well, actually, there's more to the story.
some_func(
-betty => "some value",
-wilma => "another value",
);
The hyphen on each of those lines is interpreted (correctly) as a unary
negation. The name 'betty' or 'wilma' is implicitly quoted by the big
arrow, since it is a legal identifier. Then perl applies the unary
negation to the string.
That last step may seem like a mistake to folks who are new to Perl. But
since Perl can convert strings to numbers at will, negating a string is
permitted. If the string begins with a hyphen, the hyphen is simply
removed. Otherwise, a hyphen is added. (Of course, if it begins with a
plus sign, that's removed first. And I'm leaving out some other, minor,
details; see the source if you're too curious.) Among other results, this
algorithm can negate a number in string form without first converting it
to a number. And it means that code such as what I wrote above will
normally include '-betty' as the first parameter.
The bug which the OP tripped upon is now simple(r) to explain. When 'use
integer' is in effect, perl switches to using integer-based operations
instead of the usual ones. The "integer unary negation" code in perl
mistakenly converted the string to a number before performing the usual
arithmetic negation, so the negation of 'betty' gave zero, instead of
'-betty'. Oops!
Fortunately the fix is simple. Either explicitly quote the hyphen with the
rest of the string, or upgrade perl.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 11 May 2000 08:36:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: ? How to query secured web-site
Message-Id: <Pine.GSO.4.10.10005110836040.16364-100000@user2.teleport.com>
On Wed, 10 May 2000, Songtao Chen wrote:
> Can anyone tell me how to query secured web-site (GET)
> using LWP package, assuming I have the right ID/password
> for the site ?
Have you seen the example of this in the lwpcook manpage? Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 11 May 2000 11:49:21 -0700
From: Chris <chris_heaton@mail.com>
Subject: A Simple Question
Message-Id: <2107d358.e03a754d@usw-ex0110-076.remarq.com>
Could someone please send me the code that I can enter into
my Perl script that will once executed call a webpage. For
example after the script has run to call the webpage
www.altavista.com
Any help would be appreciated.
Thanks in advance, this is urgent!
Chris.
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
------------------------------
Date: Thu, 11 May 2000 18:40:50 +0200
From: Saddek Rehal <saddek@arch.chalmers.se>
Subject: a stupid question.
Message-Id: <391AE291.6F3B7EAD@arch.chalmers.se>
What is the difference between Active Perl and Perl??
regards
Saddek
------------------------------
Date: Thu, 11 May 2000 11:55:19 -0700
From: Cure <cure@texas.net>
Subject: Re: a stupid question.
Message-Id: <391B0216.4F6E5A33@texas.net>
Perl if for unix base systems and AtivePerl is for win32 base systems
Saddek Rehal wrote:
> What is the difference between Active Perl and Perl??
> regards
> Saddek
------------------------------
Date: 11 May 2000 18:24:19 +0100
From: nobull@mail.com
Subject: Re: a stupid question.
Message-Id: <u9d7mtdmpo.fsf@wcl-l.bham.ac.uk>
Cure <cure@texas.net> writes upside down which in these parts is
usually taken as _big_ clue that he doesn't know what he's talking
about:
>
> Saddek Rehal wrote:
>
> > What is the difference between Active Perl and Perl??
>
> Perl if for unix base systems and AtivePerl is for win32 base systems
ActivePerl has a lot of stuff that is aimed primarily at the Win32
user but it runs on Unix too. Perhaps it would be better to say at
the user that thinks programming environments should be GUI.
Standard Perl now runs on Win32 too but doesn't look and fell like a
shrinkwrapped (InstallShield) Windows app. When it runs it naturally
runs as a console application (i.e. in a DOS box).
Active Perl has more of a commercial Windows product
look/feel/(smell?) but because it's based on OpenSource Perl a lot
(all?) of it is freely distributable - hence the fact that the Win32
compatibility stuff found it's way back into Perl.
This is not a full explaination. Visit the websites.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 11 May 2000 08:39:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Auto user creation.
Message-Id: <Pine.GSO.4.10.10005110838360.16364-100000@user2.teleport.com>
On Thu, 11 May 2000, Terrence Wong wrote:
> The man useradd shows that I need to use crypt on the password, but my
> perl is weak and I need help.
If everything is installed and configured correctly, you should have a
useful crypt() function in perl. See the perlfunc manpage. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 11 May 2000 11:07:12 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: baby steps with complex hashes of hashes of hashes of arrays
Message-Id: <Pine.A41.4.10.10005111050050.21492-100000@ginger.libs.uga.edu>
On 11 May 2000, The WebDragon wrote:
> In article
> <Pine.A41.4.10.10005110003530.10276-100000@ginger.libs.uga.edu>, Brad
> Baxter <bmb@ginger.libs.uga.edu> wrote:
...
> | 114 for ( 0..$count ) { print <<_end_;
> | 115 <a href="$hash{review}->[$_]"
> | target="_new">$hash{rating}->[$_]</a>
> | 116 _end_
> | 117 }
...
> Again, you have a ton of Thanks from me. This 'explains' how it works,
> better than any way I've ever found, and I can immediately break it
> apart, and put its pieces to use elsewhere. <grin>
...
You're welcome. You could also make an array of hashes, or an array of
arrays instead of the hash of arrays I did. If you care about speed, you
could implement all three and benchmark them. At the very least it would
give you a learning exercise. You've got plenty of free time, right?
I see I need to be more careful about line wraps. Hopefully the line
numbers help in that regard. One more thing:
$hash{rating}->[$_]
is almost always written as
$hash{rating}[$_]
Between square and curly brackets in these cases the arrow operator is
understood, but perl won't complain if you want to be explicit.
I'm glad you found this helpful. It won't be long before you live and
breath references and dereferences.
Cheers,
--
Brad
sub _{print((split/::/,(caller(1))[3])[1],' ')}
sub just{_}sub another{_}sub perl{_}sub hacker{_}
hacker perl another just
------------------------------
Date: 11 May 2000 17:15:08 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Behavior of split seems a bit inconsistent
Message-Id: <8fepqs$2bs$1@pegasus.csx.cam.ac.uk>
In article <u9r9b9eagw.fsf@wcl-l.bham.ac.uk>, <nobull@mail.com> wrote:
>
>A more interesting question is why does split(/#/,"",-1) not return a
>single element array with a single 0-length string "" in it.
>
>Now is _this_ a bug?
Yes. I reported it (and provided a patch, test cases etc) long ago
(I think it was before 5.004). But it turned out that some important
module (LWP ? can't remember) was exploiting the bug and broke.
So the patch had to be withdrawn.
Perhaps it's time for another try. Certainly the anomaly should be
documented, in the absence of a fix.
Mike Guy
------------------------------
Date: Thu, 11 May 2000 15:20:30 GMT
From: simeon2000@my-deja.com
Subject: CGI problems (but it IS a perl thing)
Message-Id: <8fej3a$5ng$1@nnrp1.deja.com>
Perlers,
I am not a perl newbie. I have been around a while. I am currently
working on a webmailish package for my employer. But I have hit a
snag. I am passing a server variable via CGI to the program. Here is
the problem in part-pseudocode:
<CODE>
### CGI 'SERVER' parameter
my $server = $cgi->param('SERVER');
### Make pop object;
my $pop = new Mail::POP3Client($un, $pwd, $server);
### If there is an error
if ($pop->Count == -1) {
die "Houston we have a problem";
}
</CODE>
The kicker is this, the CGI parameter contains 'pop3.domain.tld'. It
will not work. BUT, if I put code in like this,
<CODE>
#my $server = $cgi->param('SERVER');
my $server = 'pop3.domain.tld';
</CODE>
...it works fine. More oddities, I figured there might be a problem
with encoding or something so I tried this:
<CODE>
my $server_test = $cgi->param('SERVER');
my $server = 'pop3.domain.tld';
print 'Same!<BR>' if $server_test eq $server;
</CODE>
It prints out 'Same!<BR>'!!! I am at a total loss here. The variables
are EXACTLY (as far as I can tell) the same, but if I hard code it, it
works, and if it's a CGI param it fails? I am befuddled. If anyone
has ANY idea what the problem is, I will appreciate an answer and will
try anything.
--
Thomas B. Holdren
Systems's Administrator, Linux Advocate,
RMS Fan (GO RMS-LINUX!!!)
===]:-)>
--
Thomas B. Holdren
Systems's Administrator, Linux Advocate,
RMS Fan (GO RMS-LINUX!!!)
===]:-)>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 11 May 2000 15:51:06 GMT
From: simeon2000@my-deja.com
Subject: Re: CGI problems (but it IS a perl thing)
Message-Id: <8fekt1$7sa$1@nnrp1.deja.com>
Greetings again,
Sorry to waste more bandwidth, but I've narrowed it down a bit. I made
another little test page with Just the CGI module and the
Mail::POP3Client Module. Not a lot of code, here it is:
<CODE>
#!/usr/bin/perl -Tw
$ENV{ENV} = '';
$ENV{PATH} = '';
use strict;
use CGI;
use Mail::POP3Client;
### Create the CGI object
my $cgi = new CGI;
my $pop = new Mail::POP3Client(
$cgi->param('UN'),
$cgi->param('PWD'),
$cgi->param('SERVER') # contanis 'pop3.domain.tld'
);
print $cgi->header . $pop->Count;
</CODE>
If I run this from a web browser, it returns a -1 (error).
I run it interactively from the CL, it works fine.
If I replace $cgi->param('SERVER') with 'pop3.domain.tld' it works fine
from the browser.
Is there a problem between CGI and Mail::POP3Client? Then why will it
accept CGI params for name and password, but not the SERVER param?
ARRRGGGHHH!!! (hair falls out)
--Thomas B. Holdren
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 11 May 2000 09:41:20 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: CGI problems (but it IS a perl thing)
Message-Id: <Pine.GSO.4.10.10005110935040.16364-100000@user2.teleport.com>
On Thu, 11 May 2000 simeon2000@my-deja.com wrote:
> The variables are EXACTLY (as far as I can tell) the same, but if I
> hard code it, it works, and if it's a CGI param it fails?
Taint checking? It may be turned on even though you don't realize it;
here's a quick-and-dirty check for you to try:
print "Taint checks seem to be on\n"
unless eval { local $^W; unlink "$^X$^T"; 1 };
(How's that for fun variable names?) Does that tell you anything?
See perlsec for more information. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 11 May 2000 17:34:13 +0100
From: nobull@mail.com
Subject: Re: CGI problems (but it IS a perl thing)
Message-Id: <u9g0rpdp16.fsf@wcl-l.bham.ac.uk>
simeon2000@my-deja.com writes:
> The variables are EXACTLY (as far as I can tell) the same, but if I
> hard code it, it works, and if it's a CGI param it fails?
They are not the same, one is tainted. (See "perldoc perlsec" for
explaination of tainting).
There is a bug (IMNSHO) in &IO::Socket::connect in that it traps and
discards the taint error.
Does anyone know what useful purpose the eval { } in
&IO::Socket::connect serves?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 11 May 2000 15:44:18 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: cgi scripts and memory allocation
Message-Id: <mzAS4.924$Kc1.105463@news.dircon.co.uk>
On 11 May 2000 10:34:20 GMT, The WebDragon Wrote:
>
> Do cgi scripts run on unix systems need to preallocate memory, or do
> they grab more if they need more, on the fly?
>
The question should be 'do *programs* run on unix ...' a program run under
the CGI is no different to any other in this regard and Perl is no different
to most other programs in that it will attempt to allocate more memory if it
requires it.
/J\
------------------------------
Date: Thu, 11 May 2000 13:08:29 -0400
From: John J Green <jjgreen@cisco.com>
Subject: Re: Checking if Child Process is still Alive
Message-Id: <391AE90D.D527475D@cisco.com>
abeall@ipcell.com wrote:
> Does anyone know how the main process can check if a particular child
> process has died without making the main process wait.
>
> Caveat: this must work with Activeperl on a NT box but if you know how
> to do this in unix I would still like to know :).
>
> Below is an example of what I would like to do:
> $pid = fork();
> if ($pid == 0) { #Child process
> system("sdf -2mif stuff.txt");
> exit(0);
> }
>
> if ($pid != 0) { #Parent Process
> while (1) {
> sleep 5;
> if (child has not died yet) {
> print "The child is still doing something. Please be
> patient\n";
> }
> }
> }
>
> Thanks in Advance,
> Art Beall
I have tried various methods, and haven't come up with anything yet.
As other people have suggested below,
kill 0, $pid
Won't work, because it will return 1 until you reap the child, by doing
wait
or
waitpid($pid, 0)
or
waitpid($pid, WNOHANG)
Unfortunately, Win32 doesn't support the POSIX::WNOHANG value - you can
import the sub, but when invoked, it says something like 'WNOHANG not
supported
on your implementation'
The blocking wait is of little use if you want to do work.
There is no $SIG{CHLD} delivery on Win32.
If you don't need to pass a modified environment to the process (the
user's
default environment is sufficient) you can use Win32::Process
(unfortunately, I need to modify the environment)
John
------------------------------
Date: Thu, 11 May 2000 16:29:34 GMT
From: "Daniel van den Oord" <danielxx@bart.nl>
Subject: directory contents showing up ?!?
Message-Id: <OdBS4.484$Kk2.9814@Typhoon.bART.nl>
This is a multi-part message in MIME format.
------=_NextPart_000_001F_01BFBB76.DD252F80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I want to make a CGI script that displays the files in a specified =
directory So I don't have to make a database or a HTML thingy I have to =
continuously change when a file is changed !! is this possible ???
I know some CGI except that.... please help
Daniel van den Oord ( Daniel304 RTCL )
-------------------------------------------------------------------------=
-------
It's nice to be important, but it's more important to be nice
See there be good bye bye
-------------------------------------------------------------------------=
-------
Daniel304rt ResearchTriangle Community Leader
http://www.geocities.com/ResearchTriangle/Forum/5577=20
------=_NextPart_000_001F_01BFBB76.DD252F80
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3013.2600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>I want to make a CGI script that =
displays the files=20
in a specified directory So I don't have to make a database or a HTML =
thingy I=20
have to continuously change when a file is changed !! is this possible=20
???</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I know some CGI except that.... please=20
help</FONT></DIV></FONT></DIV>
<DIV>
<P>Daniel van den Oord ( Daniel304 RTCL =
)</P>
<HR>
It's nice to be important, but it's more important to be nice<BR>See =
there be=20
good bye bye
<HR>
Daniel304rt ResearchTriangle Community Leader<BR><A=20
href=3D"http://www.geocities.com/ResearchTriangle/Forum/5577">http://www.=
geocities.com/ResearchTriangle/Forum/5577</A>=20
</DIV></BODY></HTML>
------=_NextPart_000_001F_01BFBB76.DD252F80--
------------------------------
Date: Thu, 11 May 2000 09:44:01 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: directory contents showing up ?!?
Message-Id: <Pine.GSO.4.10.10005110943100.16364-100000@user2.teleport.com>
On Thu, 11 May 2000, Daniel van den Oord wrote:
> I want to make a CGI script that displays the files in a specified
> directory So I don't have to make a database or a HTML thingy I have
> to continuously change when a file is changed !! is this possible ???
Yes. Have you seen the entry for readdir in the perlfunc manpage?
Don't neglect the perlsec manpage. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 11 May 2000 15:29:57 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: DIVERTING TO A WEB PAGE
Message-Id: <8fejku$6bt$1@nnrp1.deja.com>
In article <02ae6d44.66294d2d@usw-ex0109-069.remarq.com>,
chris <cheaton@clhs.rochdale.sch.uk> wrote:
Please don't yell in your subject line . . .;^)
> I have written a PERL script to copy the contents of a form
> to a temporary file and then send it to a pre-defined e-
> mail address. This works fine, what I would like to do now
> is to direct the user to a defined web-page (URL) after the
> mail has been sent. I assume this can be written in PERL
> and be placed at the end of my existing code.
>
use the CGI.pm module, and generate a redirection header (further info
available in the documentation that comes with CGI.pm.
If you are unable or unwilling to do that, look at the documentation in
prelfaq9 "How do I redirect to another page?"
perlfaqs can be found with your perl install, or at
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html
> I would appreciate any information as this is extremly
> URGENT!!!!!
> Thanks in advance,
>
> Chris Heaton.
>
> * Sent from AltaVista http://www.altavista.com Where you can also find
related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is
Beautiful
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 11 May 2000 08:32:07 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Faster Access Time to Random Element
Message-Id: <391AD277.D429B9E9@vpservices.com>
Jeff Zucker wrote:
>
> "Randal L. Schwartz" wrote:
> >
> > That favors the longer lines.
>
> So find the average line length (which you could presumbably do once
> outside the script as soon as you had a big enough sample so you
> wouldn't have to do it for each script invocation) and do the seeks with
> that in mind?
Or if that is too crude, pad all phrases with blanks so they are fixed
length records. Disk space is cheap. :-)
(Not entirely serious, but it *would* be faster).
--
Jeff
------------------------------
Date: Thu, 11 May 2000 17:01:40 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Faster Access Time to Random Element
Message-Id: <391ae0ce.1500990@news.skynet.be>
Rodney Rindels wrote:
>I have a script that accesses a file with 3000 random lines.
>The question that I have is specific to increasing the access time to
>the specific random element in the file.
"increasing"?
Create an index file. ONCE.
open LINE, "datafile.txt" or die "Oopsidaisie: $!";
open INDEX, ">datafile.idx" or die "Batang! $!";
binmode INDEX;
do {
print INDEX pack 'N', tell LINE;
} while defined <LINE>;
Now, pick a random integer divisible by 4 between 0 (incl.) and the
length of your index file (excl.), seek in the INDEX file, and read 4
bytes. Unpack as 'N', and use number that to seek in your datafile. Read
one line.
open LINE, 'datafile.txt' or die "Poof text: $!";
open INDEX, 'datafile.idx' or die "Poof index: $!";
binmode INDEX;
seek INDEX, 4*int(rand(-s INDEX) / 4 ), 0;
sysread INDEX, $seek, 4;
seek LINE, unpack('N', $seek), 0;
$randomline = <LINE>;
print $randomline;
Tada!
--
Bart.
------------------------------
Date: 11 May 2000 10:52:39 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Faster Access Time to Random Element
Message-Id: <m13dnp9dp4.fsf@halfdome.holdit.com>
>>>>> "Jeff" == Jeff Zucker <jeff@vpservices.com> writes:
Jeff> So find the average line length (which you could presumbably do once
Jeff> outside the script as soon as you had a big enough sample so you
Jeff> wouldn't have to do it for each script invocation) and do the seeks with
Jeff> that in mind?
Well, I can have it "in mind", but there's no knowledge of that that
would help me pick the shorter lines more often. :-)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 11 May 2000 17:46:13 GMT
From: "Guillaume GERMAIN" <germain@greyinteractive.it>
Subject: file upload
Message-Id: <FlCS4.102$Yb5.429242@nnrp3.proxad.net>
Hi,
I have got a problem with a upload script in ActivePerl (Perl working on
IIS, NT Server).
In fact, the upload seems to work well for text files, but the size of the
uploaded picture file is slightly higher than the original one.
The form that makes the upload is in "post", not "get", and the encoding is
"mutipart/form-data", so I think it is correct.
I think that this may be a problem when recording the file.
Here is the bit of script that does it :
If anybody find that there is a HUGE error, I would really appreciate if he
tells me.
Thanks by advance.
my $length;
my $file_type = param(filetype);
my $size;
my $file = param('upload');
my $file_id = new_id();
$file =~ m!([^/:\\]*)$!; #capture file name
my $short_name = $1;
my $short_name_array; #temp var that will receive the short name splitted
by "."
open (SAVE,">$upload_dir/$file_id.$file_type") || die $!;
$total_size = 0;
#binary SAVE ":raw";
while ($size = read($file,$data,1024))
$total_size += $size;
print SAVE $data;
}
close SAVE;
------------------------------
Date: Thu, 11 May 2000 09:41:02 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Getting System call return data
Message-Id: <slrn8hle3e.k1b.tadmc@magna.metronet.com>
On Thu, 11 May 2000 08:42:34 -0500, John W. Komp <john.komp@uscorp.net> wrote:
>I've got a list of files which I want to search my local directory tree
>for. The list was generated in a Perl script so I'd like to stay in Perl
^^^^^^^^^^^^
>during the search. I figured I'd use the system call 'find' to do the
^^^ ^^^^
Errr, but shelling out is not "staying in Perl".
It is executing an external program.
>searching. My code fragment looks like:
>
> $findargs = ". -name \"*$item*\" -print";
> $pid = open(FINDER, "find $findargs |");
Perl FAQ, part 8:
"Why doesn't open() return an error when a pipe open fails?"
> while(<FINDER>) {
> $dirstr .= $_;
> }
You can replace that explicit and slow loop with:
{ local $/; # enable "slurp" mode
$dirstr = <FINDER>;
}
> $dirstr =~ s/\n//;
You should use tr/// when you want to work with _characters_.
Use regexes when you want to work with strings or patterns.
tr/\n//d; # strip newlines faster
> close(FINDER);
You should be checking the return value here, see the answer
to the FAQ above.
>This script works fine on my Solaris box using Perl 5.00404. On my
>NT box
Does NT have a program named 'find' ?
Does it take the same arguments as Unix find?
>is there a better
>way to do solve the problem?
use File::Find;
and do it all in native Perl.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 11 May 2000 10:48:51 -0500
From: "John W. Komp" <john.komp@uscorp.net>
Subject: Re: Getting System call return data
Message-Id: <391AD663.394EA7F4@uscorp.net>
I'm missing something here.
First you mention File::Find pod. What's pod? Perldoc does not return
anything for the File module.
Per Programming Perl, Chapter 7, the syntax is find(\&proc_name, 'dir_1',
'dir_2'). I don't want to traverse the directory tree and parse the resultant
contents myself. I just want find to find the file (i.e. find . -name
"*afile*"). I don't see how Find::File does that.
Thanks for the help so far,
-John
Ilja wrote:
> In article <391AB8CA.32A71EB0@uscorp.net>,
> "John W. Komp" <john.komp@uscorp.net> wrote:
> >
> > Hi,
> >
> > I've got a list of files which I want to search my local directory tree
> > for. The list was generated in a Perl script so I'd like to stay in Perl
> > during the search. I figured I'd use the system call 'find' to do the
> > searching. My code fragment looks like:
> >
> > $findargs = ". -name \"*$item*\" -print";
> > $pid = open(FINDER, "find $findargs |");
> > while(<FINDER>) {
> > $dirstr .= $_;
> > }
> > $dirstr =~ s/\n//;
> > close(FINDER);
> >
> > where $item is the name of the file I'm currently looking for.
> >
> > This script works fine on my Solaris box using Perl 5.00404. On my
> > NT box the script attempts to perform the find but appears to get jammed
> > returning the find results and posts a message 'Invalid access to memory
> > location.'. The NT box is running 5.005_03, binary build 517 from
> > ActiveState Tool. I'm running the script in an emacs shell in both
> > cases. The find on the NT box is from the Cygnus package.
> >
> > How do I get the find results back on the NT box or is there a better
> > way to do solve the problem?
> >
>
> Use File::Find method (AFAIK part of perl distribution). It will be faster
> and (IMHO) more portable than calling en external program (find). Colsult
> File::Find pod for details (it contains code examples so I find useless to
> post here additional ones).
>
> Good luck.
>
> Ilja.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
****************************************************
This morning I shot six holes in my freezer
I think I've got cabin fever
Somebody sound the alarm
- J. Buffett
****************************************************
------------------------------
Date: Thu, 11 May 2000 11:52:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Getting System call return data
Message-Id: <slrn8hllq6.kgo.tadmc@magna.metronet.com>
On Thu, 11 May 2000 10:48:51 -0500, John W. Komp <john.komp@uscorp.net> wrote:
>
>I'm missing something here.
>
>First you mention File::Find pod.
That is a module that is included with the perl distribution.
> What's pod?
perldoc perlpod
>Perldoc does not return
>anything for the File module.
Because there is no File module.
There is a File::Find module though. Try using the correct name :-)
perldoc File::Find
[snip jeopardist quoting of entire damn article including even .sigs ]
See:
news.announce.newusers
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3017
**************************************