[21858] in Perl-Users-Digest
Perl-Users Digest, Issue: 4062 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 4 06:06:32 2002
Date: Mon, 4 Nov 2002 03:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 4 Nov 2002 Volume: 10 Number: 4062
Today's topics:
Re: fill array with equal elements <pilsl_use@goldfisch.at>
Re: fill array with equal elements <pilsl_use@goldfisch.at>
Re: fill array with equal elements <bart.lateur@pandora.be>
Re: format print size <pkent77tea@yahoo.com.tea>
Re: Perl -e "print qq! Tips and Tricks !" <zzapper@ntlworld.com>
Re: Perl -e "print qq! Tips and Tricks !" <goldbb2@earthlink.net>
Re: Perl -e "print qq! Tips and Tricks !" <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Perl question.... (Grant)
Re: Perl question.... (Grant)
Re: Permission Error? <s.m@shoes.com>
Q re eval <penny1482@attbi.com>
Re: Q re eval <nospam@nospam.com>
Re: sub procedure question <dmueller@fhtw-berlin.de>
Re: two digit date with local time <mgjv@tradingpost.com.au>
What port number is used when using POST (Cylurian)
Re: What port number is used when using POST <tassilo.parseval@post.rwth-aachen.de>
Re: What port number is used when using POST <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: whatever happened to "static typing hints"? <flavell@mail.cern.ch>
Re: whatever happened to "static typing hints"? <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 4 Nov 2002 00:06:07 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: fill array with equal elements
Message-Id: <3dc5ac04$1@e-post.inode.at>
Garry Williams wrote:
>
> Does
>
> my @array;
> $#array = 9999;
> @array = ($value) x 10000;
>
> speed it up?
>
Suprisingly not. For small and mediumsized arrays it takes even a bit
longer (a few miliseconds for 1000 arrays of length 2000).
For very large arrays (1000000) I gain a small advantage (32.7 seconds with
presize and 33.2 seconds without).
For arrays of this size the speed for filling using the "x"-operateor is
the very same than using the "foreach ( ) { $a[$_]= }"
while "foreach ( ) { push(@a, )}" is about 20% faster !!
Looks like it pays to create an 'adaptive' function that uses different
approaches depending on the size of the array to be filled.
thnx,
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Mon, 4 Nov 2002 10:43:45 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: fill array with equal elements
Message-Id: <3dc6417a$1@e-post.inode.at>
peter pilsl wrote:
>
> Looks like it pays to create an 'adaptive' function that uses different
> approaches depending on the size of the array to be filled.
>
I just did tests for my system (celeron 700 with 396RAM):
arraysize fastest fill-method
10 ($x) x $l
100 -''-
1000 ($x) x $l with presize
5000 ($x) x $l
10000 -''-
50000 -''-
100000 -''-
300000 -''-
500000 -''- equal with push in a loop
1000000 push in a loop is 25% faster than ($x) x $l
2000000 push in a loop is ~75% faster than ($x) x $l
for the last result being suprising I print the results:
1 arrays of size 2000000
testing method 1 (24.09071s) push in a loop
testing method 2 (261.226425s) string -> split
testing method 3 (110.215413s) $a[ ]= in a loop
testing method 4 (109.462973s) -''- with presize
testing method 5 (109.143705s) pseudobinary
testing method 6 (212.164524s) rec. binary
testing method 7 (107.577326s) ($x) x $l
testing method 8 (107.734961s) -''- with presize
ps: if using presize the time needed for pesizing the array is of course
included in the total time
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Mon, 04 Nov 2002 10:48:32 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: fill array with equal elements
Message-Id: <8tjcsu04sl0pj6nomlbnbv6nqtdkodftvk@4ax.com>
Garry Williams wrote:
>Does
>
> my @array;
> $#array = 9999;
> @array = ($value) x 10000;
>
>speed it up?
I wouldn't think so. You're creating a 10000 element array and a 10000
element list, both coexist for a little while. That sounds inefficient.
Perhaps the OP could add this to his benchmarks:
$#array = 9999;
$_ = $value foreach @array;
which will replace each array item in turn, using aliasing.
--
Bart.
------------------------------
Date: Mon, 04 Nov 2002 01:36:45 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: format print size
Message-Id: <pkent77tea-1209C1.01364604112002@news-text.blueyonder.co.uk>
In article <18ad30a8.0210311537.182efde4@posting.google.com>,
neal7@yahoo.com (Mike) wrote:
> what is the best way to format the font size for a print file.
> is there some module to best handle this
If you mean what I think you mean...
If the 'print file' is a PostScript program to be sent to the printer
then there are Postscript modules on CPAN. If it's PCL then you should
look on CPAN as I have a feeling there may be PCL-related modules there.
If you're printing a plain text file and simply wish to tell the printer
"print all plain text as 8 point Courier" for example, you'll need to
find out how you can communicate with the printer, and then communicate
with the printer.
OTOH, if you want to know the best way to format the font size, then
type "12 point" into Word, highlight it and choose formatting options
from the drop-down menus or the Format menu. That's the best way to
format things.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Mon, 04 Nov 2002 10:23:01 +0000
From: zzapper <zzapper@ntlworld.com>
Subject: Re: Perl -e "print qq! Tips and Tricks !"
Message-Id: <ucicsu49r5aivcu560shi2mgugejme1cto@4ax.com>
On Sun, 03 Nov 2002 00:32:46 -0500, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:
>zzapper wrote:
>>
>> Benjamin Goldberg
>
Benjamin
I 've found that JAPH using perl -e seem to be terribly sensitive to
whether you use single or double quotes, it seems as though that
affects how the shell passes information to the perl interpreter. Can
you explain?, secondly although I've found loads of stuff on JAPH, I
haven't really found a FAQ on why & how they work
zzapper
------------------------------
Date: Mon, 04 Nov 2002 05:42:46 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl -e "print qq! Tips and Tricks !"
Message-Id: <3DC64F26.6E82531E@earthlink.net>
zzapper wrote:
>
> On Sun, 03 Nov 2002 00:32:46 -0500, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
>
> >zzapper wrote:
> >>
> >> Benjamin Goldberg
> >
>
> Benjamin
>
> I 've found that JAPH using perl -e seem to be terribly sensitive to
> whether you use single or double quotes, it seems as though that
> affects how the shell passes information to the perl interpreter.
Indeed -- you should read your shell's documentation on this; it's not
really a perl issue.
> Can you explain?, secondly although I've found loads of stuff on JAPH,
> I haven't really found a FAQ on why & how they work
All a JAPH is is a bit of code which produces the string
Just another Perl hacker,
Usually with a newline on the end. And yes, that's a comma, not a
period, after hacker. It's traditional, for some obscure reason I don't
recall.
It might be code to run with perl -e, or it might be code to run as a
regular perl script, it doesn't really matter which. It's preferred
that the code be 4 lines or fewer, and be no more than 72 columns.
Having the lines all equal lengths is also a plus, for aesthestics.
There's no *requirement* to obfuscate it (you could have something as
simple as:
print "Just another Perl hacker,\n";
), but if you do choose to obfuscate it, do your best!
(optional step) Once you've written a japh that is sufficiently pleasing
to your sense of aesthetics, use it as your mail/news signature.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 4 Nov 2002 10:40:53 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Perl -e "print qq! Tips and Tricks !"
Message-Id: <slrnascjh3.fg7.bernard.el-hagin@gdndev25.lido-tech>
In article <3DC64F26.6E82531E@earthlink.net>, Benjamin Goldberg wrote:
> zzapper wrote:
>>
>> On Sun, 03 Nov 2002 00:32:46 -0500, Benjamin Goldberg
>> <goldbb2@earthlink.net> wrote:
>>
>> >zzapper wrote:
>> >>
>> >> Benjamin Goldberg
>> >
>>
>> Benjamin
>>
>> I 've found that JAPH using perl -e seem to be terribly sensitive to
>> whether you use single or double quotes, it seems as though that
>> affects how the shell passes information to the perl interpreter.
>
> Indeed -- you should read your shell's documentation on this; it's not
> really a perl issue.
>
>> Can you explain?, secondly although I've found loads of stuff on JAPH,
>> I haven't really found a FAQ on why & how they work
>
> All a JAPH is is a bit of code which produces the string
>
> Just another Perl hacker,
>
> Usually with a newline on the end. And yes, that's a comma, not a
> period, after hacker. It's traditional, for some obscure reason I don't
> recall.
The comma is there for the same reason you'd put one after "Cheers".
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 3 Nov 2002 17:27:11 -0800
From: tonearm@email.com (Grant)
Subject: Re: Perl question....
Message-Id: <d6cf0719.0211031727.442d39f1@posting.google.com>
Bart Lateur <bart.lateur@pandora.be> wrote in message news:<lclasuk5u77u2tdmesvfamijigu1fmv21n@4ax.com>...
> Grant wrote:
>
> >Hi, I need to change strings like "Cool Posters" to "cool_posters". I
> >need to have all capitals reduced to lower-cased letters, all spaces
> >converted to "_" characters, and all "." characters simply removed.
> >Please show me how this can be done in Perl. Thanks a lot!
>
> $orig = 'Cool Posters';
> ($result = lc $orig) =~ tr/ ./_/d;
> print $result;
Works perfectly! Thanks!
- Grant
------------------------------
Date: 3 Nov 2002 17:27:35 -0800
From: tonearm@email.com (Grant)
Subject: Re: Perl question....
Message-Id: <d6cf0719.0211031727.1b62568f@posting.google.com>
"J rgen Exner" <jurgenex@hotmail.com> wrote in message news:<qXcx9.14387$7W2.6336@nwrddc01.gnilink.net>...
> Grant wrote:
> > Hi, I need to change strings like "Cool Posters" to "cool_posters". I
> > need to have all capitals reduced to lower-cased letters, all spaces
> > converted to "_" characters, and all "." characters simply removed.
> > Please show me how this can be done in Perl. Thanks a lot!
>
> Please see
> perldoc -f tr (don't forget to look at modifier d, too)
> perldoc -f lc
>
> jue
I'll check that out. Thanks!
- Grant
------------------------------
Date: Sun, 3 Nov 2002 18:08:08 -0500
From: "Newman" <s.m@shoes.com>
Subject: Re: Permission Error?
Message-Id: <usbb2ga6oaa89e@corp.supernews.com>
That was the trick. I had to use the untaint module to clean the file
names. Not sure why - they seemed okay to me.
Anyway, thanks
Newman
"Andras Malatinszky" <nobody@dev.null> wrote in message
news:3DC48818.3040204@dev.null...
>
>
> Newman wrote:
>
> > I'm using a semi-free web server (Tripod by Lycos) and trying to run a
free
> > CGI/Perl script. The script (cgiComments) allows users to comment on a
> > weblog. I am receiving the following error when trying to execute the
> > script:
> >
> > Insecure dependency in open while running with -T switch at
cgicomments.cgi
> > line 84.
>
>
> Looks like the writer of your script -- very wisely -- has turned taint
> checking on. Read the perlsec manpage to find out more about taint
> checking, but the gist of it is this: when you have the -T switch on,
>
> "You may not use data derived from outside your program to affect
> something else outside your program--at least, not by accident. All
> [...] file input [is] marked as "tainted". Tainted data may not
> be used directly or indirectly in any command that [...] modifies
> files..."
>
>
> >
> > The offending line (84):
> >
> > open (COMMENTS, ">>$comment_directory$blog_id") or die ("Can't write to
file
> > $blog_id");
> >
>
>
>
> > The offending variable, I beleive, is:
> >
> > my($comment_directory) = '/';
>
>
>
>
> >
> > I suspect that the script is unable to open a file in the comment
directory,
> > perhaps because I have not properly set the value of
"comment_directory"?
>
>
> Had your script tried and been unable to open a file in the comment
> directory, it would have died saying:
>
> Can't write to file <whatever you set $blog_id to>.
>
>
> > The FAQ documentation for my web hosting service has this to say:
> >
> > " What is the root directory for my scripts? -- The root directory for
your
> > scripts is your cgi-bin itself; if you need to fill in the root
directory,
> > it is simply "/". "
> >
> > So that's what I set "comment_directory" to.
>
>
>
> Great, so you have just given your visitor, Evil Hacker, a way to
> install a script in your cgi-bin. Good thing taint checking was on and
> Perl didn't let you do that.
>
> Please don't just turn -T off. Read perlsec and find out how you can
> untaint your data and keep your program secure.
>
------------------------------
Date: Mon, 04 Nov 2002 01:21:13 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Q re eval
Message-Id: <9Yjx9.60657$bt.109544@rwcrnsc52.ops.asp.att.net>
If I have a text file with simple Perl expressions, one per line, in terms
of variables, say
$ma1*.47 + $p[2] > .3*$ma2
can I read this in at execute time and "eval" it to TRUE or FALSE depending
on the value of the variables at that instant?
If not, is there a technique to do this task?
Thanks.
--
Dick Penny
------------------------------
Date: Sun, 3 Nov 2002 18:51:46 -0800
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Q re eval
Message-Id: <3dc5e02e_6@nopics.sjc>
"Dick Penny" <penny1482@attbi.com> wrote in message
news:9Yjx9.60657$bt.109544@rwcrnsc52.ops.asp.att.net...
> If I have a text file with simple Perl expressions, one per line, in
terms
> of variables, say
> $ma1*.47 + $p[2] > .3*$ma2
> can I read this in at execute time and "eval" it to TRUE or FALSE
depending
> on the value of the variables at that instant?
Well, try it before you post. It should work as you expect.
> If not, is there a technique to do this task?
>
> Thanks.
> --
> Dick Penny
>
>
------------------------------
Date: Mon, 04 Nov 2002 09:20:01 +0100
From: Daniel Mueller <dmueller@fhtw-berlin.de>
Subject: Re: sub procedure question
Message-Id: <aq5ajh$6j9nl$1@fu-berlin.de>
THX a lot,
that was my problem.
I think i would search many hours without success,
if there were no helpful people like you.
CU Daniel
> Daniel Mueller <dmueller@fhtw-berlin.de> writes:
>
>
>>Subject: Re: sub procedure question
>
>
> By "sub procedure" you mean "nested subroutine". Perl does not
> implement nexted subroutines in the way that, say, Pascal or GNU-C
> does. Unfortunately it doesn't throw an error (only a warning) if you
> try to use them.
>
>
>>My problem is that the procedure works once, but when using it a
>>second time, i get no data back(the size of the array seems okay, but
>>it is empty).
>
>
> Enable warnings, then read the explaintion of the warning that Perl
> gives you.
>
> It is demeaning for a human to be asked to do the work of a machine.
>
> Please do not ask people to help you find problems in your code until
> you have exhuasted the help that your computer can give you.
>
------------------------------
Date: Mon, 04 Nov 2002 00:06:50 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: two digit date with local time
Message-Id: <slrnasbek0.kud.mgjv@verbruggen.comdyn.com.au>
On Fri, 1 Nov 2002 10:38:26 -0500,
Christian Caron <nospam@nospam.org> wrote:
>
> "Chris Harris" <chris.harris@cwfi.co.fk> wrote in message
> news:apu4t7$4trc7$1@ID-134007.news.dfncis.de...
>> Hi,
>>
>> How do I get the parts of the string returned from the localtime function
> to
>> alway be in 2 digit format.
>>
>> problem is that I don't get the leading 0 for values 0 - 9.
>> e.g. today at 9:05 comes out as 1-9-5, what I want is 01-09-05.
>
> If on a Unix box, you could use:
>
> chop(my $date = `date +"%Y-%m-%d"`); # returns 2002-11-01
I wouldn't do that. The POSIX module has strftime, which is almost
identical to date(1) in functionality, but avoids calling an external
process, and is portable to any system where POSIX works. Calling
external programs for something that can be done internally is most
often not a good idea.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Can't say that it is, 'cause it ain't.
|
------------------------------
Date: 4 Nov 2002 00:11:15 -0800
From: fsromero@hotmail.com (Cylurian)
Subject: What port number is used when using POST
Message-Id: <326151f6.0211040011.30f8eeb3@posting.google.com>
I have a router using NAT with a Server using port 80. When I use
the GET method to transfer data from the client to the server, I have
no problems. When I use the POST method no data is transfered. I
know it has to do with the router, because I can run the script in the
server and it runs fine.
Any ideas?
------------------------------
Date: 4 Nov 2002 09:54:47 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: What port number is used when using POST
Message-Id: <aq5g57$gce$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Cylurian:
> I have a router using NAT with a Server using port 80. When I use
> the GET method to transfer data from the client to the server, I have
> no problems. When I use the POST method no data is transfered. I
> know it has to do with the router, because I can run the script in the
> server and it runs fine.
In which way is this related to Perl?
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Mon, 4 Nov 2002 10:07:46 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: What port number is used when using POST
Message-Id: <slrnaschj1.fg7.bernard.el-hagin@gdndev25.lido-tech>
In article <aq5g57$gce$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval
wrote:
> Also sprach Cylurian:
>
>> I have a router using NAT with a Server using port 80. When I use
>> the GET method to transfer data from the client to the server, I have
>> no problems. When I use the POST method no data is transfered. I
>> know it has to do with the router, because I can run the script in the
>> server and it runs fine.
>
> In which way is this related to Perl?
He probably has Perl installed thus making this an obvious Perl
question. Don't you know anything, Tassilo?
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Mon, 4 Nov 2002 00:34:03 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: whatever happened to "static typing hints"?
Message-Id: <Pine.LNX.4.40.0211040027390.17869-100000@lxplus071.cern.ch>
On Nov 3, Michele Dondi inscribed on the eternal scroll:
> [completely OT] Is it just a repeated typo, you writing
> "optomization", or is "optomization" something different from
> "optimization"?
The word is either 'optimisation' or 'optimization', depending on the
writer's views on the s/z choice. (The 's' spelling is the usual one
in British English, but the USAns take the other stance).
One suspects that the 'opto..' mis-spelling is due to the influence of
some other word, maybe 'optometrist'. As my late Father used to say,
"you can't be optimistic with a misty optic".
> Sorry if this is obvious, but I'm not a native english speaker (if
> that matters...).
My experience has been that non-native speakers are usually better at
spelling than the natives. And the natives are getting worse with
time.
all the best
--
Such mal ein bisschen nach WEFT und Dynamic Fonts, lies dir
durch was du gefunden hast und komme zu der Erkenntnis, dass
es besser ist, darauf zu verzichten [...] Alles was dem
User nicht nützt, schadet dem Autor. - Steffi in dciwam
------------------------------
Date: Sun, 03 Nov 2002 22:48:34 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: whatever happened to "static typing hints"?
Message-Id: <3DC5EE12.7C1AC8B@earthlink.net>
Michele Dondi wrote:
>
> On Wed, 30 Oct 2002 18:04:57 -0500, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
>
> >Yes, it would ... unless at the first use of this optomization,
>
> [completely OT] Is it just a repeated typo, you writing
> "optomization", or is "optomization" something different from
> "optimization"?
It's a repeated typo.
> Sorry if this is obvious, but I'm not a native english speaker (if
> that matters...).
To a non-native speaker, all english words which are the slightest bit
unfamiliar get quite a bit of scrutiny; native speakers are generally
more lazy in checking their spelling.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4062
***************************************