[22894] in Perl-Users-Digest
Perl-Users Digest, Issue: 5114 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 13 00:05:53 2003
Date: Thu, 12 Jun 2003 21:05:09 -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 Thu, 12 Jun 2003 Volume: 10 Number: 5114
Today's topics:
Bad code example in perlsub doc <occitan@esperanto.org>
Re: Bad code example in perlsub doc <emschwar@pobox.com>
Re: Bad code example in perlsub doc <usenet@dwall.fastmail.fm>
Re: How to I arrange for a socket connection to time ou <ben.goldberg@hotpop.com>
Re: need the ascii set for arrow down <ben.goldberg@hotpop.com>
print operand file name <mhearse@hotmail.com>
Re: Producing a graph <asu1@c-o-r-n-e-l-l.edu>
Re: Producing a graph <mgjv@tradingpost.com.au>
Question: Install Dir.pm Thunder9_NOSPAM@dsemail.net
Re: Search through Array and evaluate the two <jkeen@concentric.net>
Re: Search through Array and evaluate the two <mgjv@tradingpost.com.au>
Sort upper- and lowercase strings alphabetically <skinny@bones.com>
Re: Sort upper- and lowercase strings alphabetically <mbudash@sonic.net>
Re: Sort upper- and lowercase strings alphabetically <mgjv@tradingpost.com.au>
Re: Sort upper- and lowercase strings alphabetically <skinny@bones.com>
Re: SQL Problem - Select returns nothing (Dennis Macdonald)
Timers + callbacks (Tarak Parekh)
Re: Timers + callbacks (Damian James)
Re: unbelievable doco bug?? in 5.8.0 (the_rev_dharma_roadkill)
Re: Using GET with $ENV{'QUERY_STRING'} <flavell@mail.cern.ch>
Re: Which value is tha largest(benchmarked) <glex_nospam@qwest.net>
Re: Which value is tha largest(benchmarked) <usenet@dwall.fastmail.fm>
Re: Which value is tha largest(benchmarked) <mgjv@tradingpost.com.au>
Re: Which value is tha largest <bdonlan@bd-home-comp.no-ip.org>
Re: Which value is tha largest <krahnj@acm.org>
Re: Which value is tha largest (Jay Tilton)
Re: why does perl do it? (i5513)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 13 Jun 2003 00:03:28 +0200
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Bad code example in perlsub doc
Message-Id: <20030613000328.3167a70d.occitan@esperanto.org>
Hi,
perlsub contains the following example:
sub popmany {
my $aref;
my @retlist =3D ();
foreach $aref ( @_ ) {
push @retlist, pop @$aref;
}
return @retlist;
}
where I've timed this equivalent code as being almost 30% faster:
sub popmany {
map { pop @$_ } @_;
}
I'd say such code should not be in the documentation. Should this be a
bug-report?
Btw. I would expect map to take @_ as a default argument...
coralament / best Gr=F6tens / liebe Gr=FC=DFe / best regards / elkorajn sal=
utojn
Daniel Pfeiffer
-- GPL 3: take the wind out of Palladium's sails! --
------
-- My other stuff here too, make.pl, sawfish...: --
------
-- http://dapfy.bei.t-online.de/ --
------------------------------
Date: 12 Jun 2003 16:36:51 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Bad code example in perlsub doc
Message-Id: <etoznkmudmk.fsf@wormtongue.emschwar>
Daniel Pfeiffer <occitan@esperanto.org> writes:
> perlsub contains the following example:
<snip 'popmany' example from perlsub>
> where I've timed this equivalent code as being almost 30% faster:
>
> sub popmany {
> map { pop @$_ } @_;
> }
>
> I'd say such code should not be in the documentation. Should this be a
> bug-report?
I don't think so. The code in perlsub is much clearer and obvious
what it's doing. The purpose of examples in perlsub is not to show
the fastest way of doing something, but to be clear and obvious about
what they're doing. Simple things like
forech my $aref ( @_ ) {
...
}
make it more obvious that each element of @_ is an array ref. Your
example is better for someone who already knows Perl, and thus doesn't
need perlsub. :)
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Fri, 13 Jun 2003 01:29:28 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Bad code example in perlsub doc
Message-Id: <Xns9398DA9E9C360dkwwashere@216.168.3.30>
Eric Schwartz <emschwar@pobox.com> wrote:
> Daniel Pfeiffer <occitan@esperanto.org> writes:
[slow code in perlsub]
>> I'd say such code should not be in the documentation. Should this be a
>> bug-report?
>
> I don't think so. The code in perlsub is much clearer and obvious
> what it's doing. The purpose of examples in perlsub is not to show
> the fastest way of doing something, but to be clear and obvious about
> what they're doing.
It wouldn't hurt to have an example of faster code*, but I doubt that it's
high on the list of priorities for the maintainers of the docs.
* I mistyped "coed" at first. Can we have fast coeds in perlsub? That
would be more fun than faster code.
------------------------------
Date: Thu, 12 Jun 2003 21:42:22 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <3EE92BFE.9607C4E9@hotpop.com>
John Brock wrote:
> One other question: Programming Perl's description of sysread()
> say something about the user needing to be "prepared to handle the
> problems (like interrupted syscalls) that standard I/O normally
> handles for you". Do you have any idea what they are talking about?
Yes. If you fork(), and then your child process dies, then your process
will be interrupted by a SIGCHLD signal. This causes the C-level read()
function that perl's sysread() does to return -1, with errno set to -1.
Depending on your perl version, this may cause your call to sysread() to
return undef(), with $! set to &Errno::INTR().
AFAIK, with standard I/O, when the underlying read() call returns -1,
with errno set to EINTR, it will call read() again.
> And is it possible that using recv() instead of sysread() also makes
> life easier in this respect?
AFAIK, recv() acts just like sysread() in this respect.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Thu, 12 Jun 2003 22:24:17 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: need the ascii set for arrow down
Message-Id: <3EE935D1.C35D77DB@hotpop.com>
gerrym wrote:
>
> Hello
> I have aq ascii menu on a linux box which uses the arrow up and down
> to nagivate the menus.
> I want to automate it using Perl Expect.pm, but I cannot find the
> character set I need to send.
>
> Anyone come across a table of these before.
As others have said, you need a sequence of characters, not a single
character. Further, the sequence depends on what type of terminal the
program you are talking to thinks you are.
So, if your program on the linux box thinks that you are actually a
vt100 terminal, it will be looking for a different sequence than it
would if it thought that you were a <fubar> terminal.
The way you discover this string is:
use POSIX ();
use constant MY_OSPEED => do {
(my $termios = new POSIX::Termios)->getattr;
$termios->getospeed() || 9600;
};
use Term::Cap;
# "Tgetent" is how Term::Cap spells "new".
my $term_capabilities = Term::Cap->Tgetent( {
TERM => undef, # guess based on my environment
OSPEED => MY_OSPEED,
} );
# This is optional -- it does nothing but confirm that
# the requested capabilites exist, and die()s elsewise.
$term_capabilities->Trequire(qw/ku/);
# get the string for "kursor up".
my $cursor_up_string = $term_capabilities->Tput("ku", 0, undef);
[untested]
You can replace the undef in the ->Tgetent call with the name of a
terminal which you want to emulate.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Thu, 12 Jun 2003 20:17:59 -0700
From: "mhearse" <mhearse@hotmail.com>
Subject: print operand file name
Message-Id: <sebGa.2396$Wl.510@fe03.atl2.webusenet.com>
I've recently developed a script to validate simple macro commands. This
script may be run on as many as 200 files at once (macro_valid.pl *).
Currently it prints only the errors detected (no way to tell which errors go
with which filename). I need a way to print the filename when an error is
detected. Possibly some way to read the filename into input, and print it
if an error is detected. Any suggestions?
------------------------------
Date: 13 Jun 2003 01:09:44 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Producing a graph
Message-Id: <Xns9398D746884C2asu1cornelledu@132.236.56.8>
Music Man <musicman@hotmail.com> wrote in
news:MPG.19527ff75c6d376a989711@news.siol.net:
> In article <pan.2003.06.12.08.08.53.230411@kamelfreund.de>,
> bigj@kamelfreund.de says...
>> slash wrote at Wed, 11 Jun 2003 20:10:54 -0700:
>>
>> > I am new to Perl and a very bad programmer and am fiddling with a
>> > problem of mapping a certain output to a graph data structure. I
>> > think I can do this in Java but in Perl, I don't even know where to
>> > begin!
<snip>
> I use GNUPlot with Perl
see http://www.math.fau.edu/locke/graphthe.htm
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 13 Jun 2003 01:29:48 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Producing a graph
Message-Id: <slrnbeia8e.luq.mgjv@verbruggen.comdyn.com.au>
On Thu, 12 Jun 2003 13:18:35 +0200,
Music Man <musicman@hotmail.com> wrote:
> In article <pan.2003.06.12.08.08.53.230411@kamelfreund.de>,
> bigj@kamelfreund.de says...
>> slash wrote at Wed, 11 Jun 2003 20:10:54 -0700:
>>
>> > I am new to Perl and a very bad programmer and am fiddling with a
>> > problem of mapping a certain output to a graph data structure. I think
>> > I can do this in Java but in Perl, I don't even know where to begin!
[snip]
> I use GNUPlot with Perl
The OP needs a graph data structure. Not a chart-type graph.
Martien
--
|
Martien Verbruggen | Little girls, like butterflies, need no
Trading Post Australia | excuse - Lazarus Long
|
------------------------------
Date: Fri, 13 Jun 2003 04:04:53 GMT
From: Thunder9_NOSPAM@dsemail.net
Subject: Question: Install Dir.pm
Message-Id: <8njievk6p16hg4ftp4dh141kk1b922thtg@4ax.com>
On my corporate unix system, aix version 4.3.3.0, we are missing
Dir.pm. It should be under /lib/5.00503/aix/IO/ but I only have the
following files:
File.pm Select.pm Socket.pm Handle.pm Seekable.pm Pipe.pm IO.pm
What's the easiest way to get Dir.pm and use it for my code? I could
just put it in my home directory.
Alternatively, what would be a method for getting a reference to a
file handle into a scaler that could be used by readdir? I'm trying
to do recursion here with a directory handle, and wanted to avoid use
of explicit file handle variables.
Regards,
Thunder9
------------------------------
Date: 13 Jun 2003 02:37:34 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Search through Array and evaluate the two
Message-Id: <bcbdde$99k@dispatch.concentric.net>
"Steven Kuo" <skuo@mtwhitney.nsc.com> wrote in message
news:Pine.GSO.4.21.0306121312350.23188-100000@mtwhitney.nsc.com...
> On 12 Jun 2003, James E Keenan wrote:
>
> (Snipped) ...
> > my @barcodes = qw|alpha beta gamma delta alpha epsilon beta zeta eta
> > theta gamma|;
> > my %seenlast = ();
> > for (my $i=0; $i<=$#barcodes; $i++) {
> > if (defined $seenlast{$barcodes[$i]}) {
> > $seenlast{$barcodes[$i]} = $i if $i >
$seenlast{$barcodes[$i]};
> > } else {
> > $seenlast{$barcodes[$i]} = $i;
> > }
> > }
>
> Seems simpler to replace the 'for' loop with a hash slice:
>
> @seenlast{@barcodes} = (0 .. $#barcodes);
>
True ... except that if one of the values were 'undef', you would get a
warning about an uninitialized value when you printed out the hash. How
would you accommodate that possibility using the hash slice?
------------------------------
Date: 13 Jun 2003 03:54:34 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Search through Array and evaluate the two
Message-Id: <slrnbeiint.luq.mgjv@verbruggen.comdyn.com.au>
On 13 Jun 2003 02:37:34 GMT,
James E Keenan <jkeen@concentric.net> wrote:
>
> "Steven Kuo" <skuo@mtwhitney.nsc.com> wrote in message
> news:Pine.GSO.4.21.0306121312350.23188-100000@mtwhitney.nsc.com...
>> On 12 Jun 2003, James E Keenan wrote:
>>
>> (Snipped) ...
>> > my @barcodes = qw|alpha beta gamma delta alpha epsilon beta zeta eta
>> > theta gamma|;
>> > my %seenlast = ();
>> > for (my $i=0; $i<=$#barcodes; $i++) {
>> > if (defined $seenlast{$barcodes[$i]}) {
>> > $seenlast{$barcodes[$i]} = $i if $i >
> $seenlast{$barcodes[$i]};
$i will always be larger than $seenlast{$barcodes[$i]}, since $i
monotonically increases. I also don't think you meant to use
C<defined>, but C<exists>. In any case, it makes no difference whether
or not the hash element already exists. You could simply use the
assignment in the else clause, and get the same effect.
>> > } else {
>> > $seenlast{$barcodes[$i]} = $i;
>> > }
>> > }
>>
>> Seems simpler to replace the 'for' loop with a hash slice:
>>
>> @seenlast{@barcodes} = (0 .. $#barcodes);
>>
> True ... except that if one of the values were 'undef', you would get a
> warning about an uninitialized value when you printed out the hash. How
> would you accommodate that possibility using the hash slice?
Euhm... Not print out the hash?
Seriously, though, what do you mean by "print out the hash"?
Extrapolate it in a double-quoted context? You'll get warnings with
your code as well if you enable warnings, and if there are undefined
elements in @barcodes.
If you have to deal specifically with undefined values in @barcodes,
you will have to deal with that. How you deal with it depends on what
that undefined value means.
The following three methods all end up with the same hash contents:
#!/usr/local/bin/perl
use strict;
use warnings;
my @barcodes =
qw|alpha beta gamma delta alpha epsilon beta zeta eta theta gamma|;
my %seenlast1;
for (my $i=0; $i<=$#barcodes; $i++) {
if (defined $seenlast1{$barcodes[$i]}) {
$seenlast1{$barcodes[$i]} = $i if $i > $seenlast1{$barcodes[$i]};
} else {
$seenlast1{$barcodes[$i]} = $i;
}
}
my %seenlast2;
for (my $i=0; $i < @barcodes; $i++) {
$seenlast2{$barcodes[$i]} = $i;
}
my %seenlast3;
@seenlast3{@barcodes} = (0 .. $#barcodes);
Martien
--
|
Martien Verbruggen | My friend has a baby. I'm writing down all
Trading Post Australia | the noises the baby makes so later I can ask
| him what he meant - Steven Wright
------------------------------
Date: Fri, 13 Jun 2003 00:46:05 GMT
From: Big Slim <skinny@bones.com>
Subject: Sort upper- and lowercase strings alphabetically
Message-Id: <120620031946274704%skinny@bones.com>
Perl's sort command seems to think uppercase strings come before
lowercase strings. Is there a way to sort an array alphabetically
regardless of case without actually changing any of the values in the
hash?
TIA--Big Slim
------------------------------
Date: Fri, 13 Jun 2003 00:56:54 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Sort upper- and lowercase strings alphabetically
Message-Id: <mbudash-64C331.17565312062003@typhoon.sonic.net>
In article <120620031946274704%skinny@bones.com>,
Big Slim <skinny@bones.com> wrote:
> Perl's sort command seems to think uppercase strings come before
> lowercase strings. Is there a way to sort an array alphabetically
> regardless of case without actually changing any of the values in the
> hash?
>
> TIA--Big Slim
perldoc -f sort
then search for 'case-insensitive'
--
Michael Budash
------------------------------
Date: 13 Jun 2003 01:13:30 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Sort upper- and lowercase strings alphabetically
Message-Id: <slrnbei99s.luq.mgjv@verbruggen.comdyn.com.au>
On Fri, 13 Jun 2003 00:46:05 GMT,
Big Slim <skinny@bones.com> wrote:
> Perl's sort command seems to think uppercase strings come before
> lowercase strings. Is there a way to sort an array alphabetically
^^^^^
> regardless of case without actually changing any of the values in the
> hash?
^^^^
Array or hash? Not that it matters...
Use a sort subroutine that compares case-insenitively
@sorted = sort { lc($a) cmp lc($b) } @unsorted;
This is probably not the most efficient method, depending on how long
the strings in @unsorted are and how large your arrays are. Each
string will be lowercased more than once. A Schwartzian transform,
which does that operation only once per element at the cost of more
memory, the creation of some anonymous arrays and some dereferences,
probably is more efficient:
@sorted = map { $_[1] }
sort { $a->[0] cmp $b->[0] }
map { [ lc($_), $_ ] } @unsorted;
Also see the Perl FAQ, section 4, "How do I sort an array by
(anything)?", and the entry on sort() in perlfunc. Those two together
contain the full answer to this question.
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy from a
Trading Post Australia | rich salesperson.
|
------------------------------
Date: Fri, 13 Jun 2003 02:14:03 GMT
From: Big Slim <skinny@bones.com>
Subject: Re: Sort upper- and lowercase strings alphabetically
Message-Id: <120620032114241338%skinny@bones.com>
In article <slrnbei99s.luq.mgjv@verbruggen.comdyn.com.au>, Martien
Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Fri, 13 Jun 2003 00:46:05 GMT,
> Big Slim <skinny@bones.com> wrote:
> > Perl's sort command seems to think uppercase strings come before
> > lowercase strings. Is there a way to sort an array alphabetically
> ^^^^^
> > regardless of case without actually changing any of the values in the
> > hash?
> ^^^^
>
> Array or hash? Not that it matters...
>
>
> Use a sort subroutine that compares case-insenitively
>
> @sorted = sort { lc($a) cmp lc($b) } @unsorted;
>
> This is probably not the most efficient method, depending on how long
> the strings in @unsorted are and how large your arrays are. Each
> [snip]
I meant array, sorry. This works great! My arrays are very small, so
the first method works fine. I'll check out the references you
mentioned.
Thanks--Big Slim
------------------------------
Date: 12 Jun 2003 17:39:00 -0700
From: newsgroups@bandwood.com (Dennis Macdonald)
Subject: Re: SQL Problem - Select returns nothing
Message-Id: <d98b592e.0306121639.3fcc76b9@posting.google.com>
This explains it - thanks very much. I thought it returned the number
of rows and was using it to determine if I needed to fetch. I was
wrong!!
I don't know how much time I wasted on this.
Regards,
Dennis.
Brian McCauley <nobull@mail.com> wrote in message news:<u9r85zwl62.fsf@wcl-l.bham.ac.uk>...
> newsgroups@bandwood.com (Dennis Macdonald) writes:
>
> > I have the following code and it inserts into the database correctly
> > but the select straight after it always returns no records.
>
> How do you know? The code you posted makes no attempt to read any
> records from the database SELECT statement handle.
>
> See also the description of the execute() method in "perldoc DBI".
> Note in particular the paragraph:
>
> For "SELECT" statements, execute simply "starts" the
> query within the database engine. Use one of the fetch
> methods to retrieve the data after calling "execute".
> The "execute" method does not return the number of
> rows that will be returned by the query (because most
> databases can't tell in advance), it simply returns a
> true value.
------------------------------
Date: 12 Jun 2003 17:02:46 -0700
From: tarakparekh@yahoo.com (Tarak Parekh)
Subject: Timers + callbacks
Message-Id: <24853e23.0306121602.26e778b9@posting.google.com>
Hello,
I was wondering if there was a Timer module in perl
with a callback mechanism, such that on timeout expiration
it invokes the callback function (periodically or one-shot)
I tried a search on CPAN but was unsuccessful in finding a
module. I might have missed something.
thanks,
tarak
------------------------------
Date: 13 Jun 2003 00:36:19 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Timers + callbacks
Message-Id: <slrnbei742.3i3.damian@puma.qimr.edu.au>
On 12 Jun 2003 17:02:46 -0700, Tarak Parekh said:
>Hello,
>
>I was wondering if there was a Timer module in perl
>with a callback mechanism, such that on timeout expiration
>it invokes the callback function (periodically or one-shot)
>
>I tried a search on CPAN but was unsuccessful in finding a
>module. I might have missed something.
Module? See the perlfunc entry for alarm() and the perlvar entry for
%SIG.
#!perl
use warnings;
use strict;
$| = 1;
$SIG{ALRM} = sub { die "\bBoo!\n" };
my $tw = make_twirly();
alarm 5;
print $tw->() while 1;
sub make_twirly {
my @chars = qw[ / | \ - ];
my $i = 0;
sub { "\b"x($i>0) . $chars[ $i++ % @chars ]}
}
--damian
------------------------------
Date: 12 Jun 2003 15:40:35 -0700
From: doug.hendricks@tnzi.com (the_rev_dharma_roadkill)
Subject: Re: unbelievable doco bug?? in 5.8.0
Message-Id: <fb91dbec.0306121440.463ec179@posting.google.com>
I hide my head in shame.
Bob Walton> You are wrong. From perldoc perlsyn: ...
bob (different guy)> The NEXT 2 sentences on the page you quote from
says: ...
OK, I was having a bad day. Special thanks to Mr. Walton for his
prompt email. I think I'll up my medication and avoid operating heavy
machinery for awhile.
------------------------------
Date: Fri, 13 Jun 2003 01:40:06 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Using GET with $ENV{'QUERY_STRING'}
Message-Id: <Pine.LNX.4.53.0306130128280.24937@lxplus011.cern.ch>
On Thu, Jun 12, Bob inscribed on the eternal scroll:
> In the HTML form I have these following paramters passed from this form into
> a Perl module.
> ?item=doo200&action=sell&amount=4&Submit=Submit+Query
er, yes...
> which go into QUERY_STRING
Indeed they do, if you're using a GET request. But if the action is
"sell", then you surely don't want to be using a GET request.
The whole thing proceeds in accordance with an interworking
specification (perlfaq9 has pointers... well, best not use a faq
version earlier than 5.8.* - but I would say that, wouldn't I? ;-).
> the doco I have says to do it like this . . .
> @values = split(/&/,$ENV{'QUERY_STRING'});
> foreach $input (@values)
> {($one, $two) = split(/=/,$input);
Oh dear. Which 'doco' would that be, then? I don't think it would be
anything we use in production around here, although it can be
interesting as a student exercise - to see what can go wrong.
One of the problems with using CGI.pm is that there aren't any
comments in the decoding to show just why things are done that way and
not another, so the student doesn't get to learn from that just where
the pitfalls are. But nevertheless...
> if I want to use the values 'd00200' and 'sell' how do I express it to get
> at these values and evaluate these to do whatever processing required ?
I would strongly recommend following the tutorials associated with
CGI.pm, and/or the worked examples (online) which accompany the
author's book.
But since your request does not appear to be idempotent, you really
ought to (I suspect the lawyers would say 'must') be using a POST
transaction. CGI.pm happily handles that too.
have fun.
------------------------------
Date: Thu, 12 Jun 2003 18:05:38 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Which value is tha largest(benchmarked)
Message-Id: <YG7Ga.67$%C6.52356@news.uswest.net>
TruthXayer wrote:
> "David K. Wall" wrote:
>
>>TruthXayer <TruthXayer@yahoo.com> wrote:
>>
>>
>>>"David K. Wall" wrote:
>>>
>>>>sub max {
>>>> my $max = shift;
>>>> $max = $_ > $max ? $_ : $max foreach @_;
>>>> return $max;
>>>>}
>>>>
>>>>my $maximum = max($one, $two, $tre, $for);
>>>
>>>
>>>Interessting , I benchmarked two cases:
>>> -> small unsorted arrays
>>> -> big sorted arrays (got sorted much quicker with right
>>>ordering)
>>> -> big reverse sorted (got awfully slow)
>>>
>>>So keep those arrays sorted as much as possible to improve
>>>performance else you are done
>>>for!
>>
>>What does sorting have to do with the code I posted?
>
>
> Your code is faster than other examples posted here.
> But its speed is also affected depending on whether
> input is sorted or not , check it out with Benchmark.
Errr.. Your benchmark, based on your description (always show code for
benchmarks..), probably didn't take into account the time it takes to
sort. Also, if the input/data is already sorted, then the max is either
$arr[0] or $arr[-1], depending on order, which is about as fast as it gets.
Remember, the Universe favors disorder, so only sort when needed. :-)
------------------------------
Date: Fri, 13 Jun 2003 01:22:44 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Which value is tha largest(benchmarked)
Message-Id: <Xns9398D97A22E35dkwwashere@216.168.3.30>
TruthXayer <TruthXayer@yahoo.com> wrote:
> "David K. Wall" wrote:
>> What does sorting have to do with the code I posted?
>
> Your code is faster than other examples posted here.
They never pretended to be fast. Quick-and-dirty to write for small
lists, yes, but fast, no.
> But its speed is also affected depending on whether
> input is sorted or not , check it out with Benchmark.
I did. I saw no noticeable difference in execution times with different
inputs of the same size, and I ran variations of the code below a number
of times. That was no surprise, since the function looks at every item
in the list fed to it. Looks like O(n).
use strict;
use warnings;
use Benchmark qw/timethese cmpthese/;
sub max {
my $max = shift;
$max = $_ > $max ? $_ : $max foreach @_;
return $max;
}
for my $n (1e1, 1e2, 1e3, 1e4, 1e5, 1e6) {
my @ra1 = (1..$n);
my @ra2;
push @ra2, rand for 1..$n;
my @ra3 = reverse @ra1;
print "n = $n\n\n";
my $results = timethese(2000000, {
'1 to n' => 'my $m = max(@ra1)',
'random' => 'my $m = max(@ra2)',
'n to 1' => 'my $m = max(@ra2)',
});
print "\n";
cmpthese $results;
print "\n----\n\n";
}
Output:
n = 10
Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
1 to n: 3 wallclock secs ( 3.50 usr + 0.00 sys = 3.50 CPU) @
571428.57/s (n=2000000)
n to 1: 3 wallclock secs ( 3.56 usr + 0.00 sys = 3.56 CPU) @
561324.73/s (n=2000000)
random: 3 wallclock secs ( 3.58 usr + 0.00 sys = 3.58 CPU) @
559127.76/s (n=2000000)
Rate random n to 1 1 to n
random 559128/s -- -0% -2%
n to 1 561325/s 0% -- -2%
1 to n 571429/s 2% 2% --
----
n = 100
Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
1 to n: 3 wallclock secs ( 3.56 usr + 0.00 sys = 3.56 CPU) @
561324.73/s (n=2000000)
n to 1: 5 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU) @
568828.21/s (n=2000000)
random: 4 wallclock secs ( 3.56 usr + 0.00 sys = 3.56 CPU) @
561482.31/s (n=2000000)
Rate 1 to n random n to 1
1 to n 561325/s -- -0% -1%
random 561482/s 0% -- -1%
n to 1 568828/s 1% 1% --
----
n = 1000
Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
1 to n: 3 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU) @
568828.21/s (n=2000000)
n to 1: 3 wallclock secs ( 3.58 usr + 0.01 sys = 3.59 CPU) @
556483.03/s (n=2000000)
random: 3 wallclock secs ( 3.61 usr + 0.00 sys = 3.61 CPU) @
554170.13/s (n=2000000)
Rate random n to 1 1 to n
random 554170/s -- -0% -3%
n to 1 556483/s 0% -- -2%
1 to n 568828/s 3% 2% --
----
n = 10000
Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
1 to n: 3 wallclock secs ( 3.58 usr + 0.00 sys = 3.58 CPU) @
558971.49/s (n=2000000)
n to 1: 3 wallclock secs ( 3.56 usr + 0.00 sys = 3.56 CPU) @
561482.31/s (n=2000000)
random: 5 wallclock secs ( 3.63 usr + 0.02 sys = 3.64 CPU) @
549299.64/s (n=2000000)
Rate random 1 to n n to 1
random 549300/s -- -2% -2%
1 to n 558971/s 2% -- -0%
n to 1 561482/s 2% 0% --
----
n = 100000
Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
1 to n: 5 wallclock secs ( 3.55 usr + 0.00 sys = 3.55 CPU) @
563856.78/s (n=2000000)
n to 1: 4 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU) @
568990.04/s (n=2000000)
random: 4 wallclock secs ( 3.63 usr + 0.00 sys = 3.63 CPU) @
551724.14/s (n=2000000)
Rate random 1 to n n to 1
random 551724/s -- -2% -3%
1 to n 563857/s 2% -- -1%
n to 1 568990/s 3% 1% --
----
n = 1000000
Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
1 to n: 4 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU) @
568990.04/s (n=2000000)
n to 1: 3 wallclock secs ( 3.56 usr + 0.00 sys = 3.56 CPU) @
561324.73/s (n=2000000)
random: 3 wallclock secs ( 3.53 usr + 0.02 sys = 3.55 CPU) @
563856.78/s (n=2000000)
Rate n to 1 random 1 to n
n to 1 561325/s -- -0% -1%
random 563857/s 0% -- -1%
1 to n 568990/s 1% 1% --
----
------------------------------
Date: 13 Jun 2003 02:01:03 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Which value is tha largest(benchmarked)
Message-Id: <slrnbeic31.luq.mgjv@verbruggen.comdyn.com.au>
On Fri, 13 Jun 2003 01:22:44 -0000,
David K. Wall <usenet@dwall.fastmail.fm> wrote:
> TruthXayer <TruthXayer@yahoo.com> wrote:
>
>> "David K. Wall" wrote:
>>> What does sorting have to do with the code I posted?
>>
>> Your code is faster than other examples posted here.
>
> They never pretended to be fast. Quick-and-dirty to write for small
> lists, yes, but fast, no.
>
>> But its speed is also affected depending on whether
>> input is sorted or not , check it out with Benchmark.
>
> I did. I saw no noticeable difference in execution times with different
> inputs of the same size, and I ran variations of the code below a number
> of times. That was no surprise, since the function looks at every item
> in the list fed to it. Looks like O(n).
And that's what it should be.
[snip]
> for my $n (1e1, 1e2, 1e3, 1e4, 1e5, 1e6) {
> my @ra1 = (1..$n);
This will fill @ra1 with integers,
> my @ra2;
> push @ra2, rand for 1..$n;
This will fill @ra2 with doubles. It's probably better to make sure
they're the same thing. Either floats everywhere, or ints everywhere.
> my @ra3 = reverse @ra1;
> print "n = $n\n\n";
> my $results = timethese(2000000, {
I generally use something like -3 as the first argument here. It's
less fiddly to get right, and you can predict how long you need to
wait.
> '1 to n' => 'my $m = max(@ra1)',
> 'random' => 'my $m = max(@ra2)',
> 'n to 1' => 'my $m = max(@ra2)',
Be careful with lexicals and eval, which is what is used in this case.
You're not actually finding the max() of anything (in the eval you
won't see that lexical). Also, the last @ra2 should probably be @ra3.
'1 to n' => sub { my $m = max(@ra1) },
'random' => sub { my $m = max(@ra2) },
'n to 1' => sub { my $m = max(@ra3) },
> });
> print "\n";
> cmpthese $results;
> print "\n----\n\n";
> }
Fixing the above gives a more correct comparison.
I haven't actually run it, but I can imagine that you'd still find a
small disadvantage for the '1 to n' case, because it has to assign a
different value to $max for each element inspected. The 'n to 1' case
assigns the same value every time (I'd fix the subroutine as well: why
assign $max to $max ever?). Perl might optimise that sort of thing
internally, or not. It probably does. I don't think it'll make an
enormous amount of difference anyway.
> n = 10
>
> Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
> 1 to n: 3 wallclock secs ( 3.50 usr + 0.00 sys = 3.50 CPU) @
> 571428.57/s (n=2000000)
^^^^^^^^^^^
> n = 1000000
>
> Benchmark: timing 2000000 iterations of 1 to n, n to 1, random...
> 1 to n: 4 wallclock secs ( 3.52 usr + 0.00 sys = 3.52 CPU) @
> 568990.04/s (n=2000000)
^^^^^^^^^^^
I don't think there are many machines where a loop that iterates
1000000 times takes as little time as one that iterates 10 times.
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
Trading Post Australia | inexactitude.
|
------------------------------
Date: Thu, 12 Jun 2003 19:55:11 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Which value is tha largest
Message-Id: <pan.2003.06.12.23.55.08.48998@bd-home-comp.no-ip.org>
On Thu, 12 Jun 2003 12:59:37 +0000, Michael Hill wrote:
> Without having to have a nexted if else syntax does anyone know an easy
> way to determine which value is the largest?
>
> $one = 3;
> $two = 5;
> $tre = 1;
> $for = 10;
>
> $largest = ( );
>
> Mike
$largest = (sort ($one, $two, $tre, $for))[-1];
------------------------------
Date: Fri, 13 Jun 2003 00:59:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Which value is tha largest
Message-Id: <3EE921F2.CE871C3@acm.org>
bd wrote:
>
> On Thu, 12 Jun 2003 12:59:37 +0000, Michael Hill wrote:
>
> > Without having to have a nexted if else syntax does anyone know an easy
> > way to determine which value is the largest?
> >
> > $one = 3;
> > $two = 5;
> > $tre = 1;
> > $for = 10;
> >
> > $largest = ( );
>
> $largest = (sort ($one, $two, $tre, $for))[-1];
$ perl -le'
$one = 3;
$two = 5;
$tre = 1;
$for = 10;
$largest = (sort ($one, $two, $tre, $for))[-1];
print $largest;
'
5
Gee, I thought that 10 was larger than 5.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 13 Jun 2003 03:57:44 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Which value is tha largest
Message-Id: <3ee94b81.109896666@news.erols.com>
Michael Hill <hillmw@ram.lmtas.lmco.com> wrote:
: Without having to have a nexted if else syntax does anyone know an easy
: way to determine which value is the largest?
:
: $one = 3;
: $two = 5;
: $tre = 1;
: $for = 10;
:
: $largest = ( );
use List::Util qw(max);
my $largest = max( $one, $two, $tre, $for );
------------------------------
Date: 12 Jun 2003 15:25:54 -0700
From: i5513@hotmail.com (i5513)
Subject: Re: why does perl do it?
Message-Id: <a657ec02.0306121425.cf214a6@posting.google.com>
Thanks you!!
Very interesting article at Perl Articles, I didn't know about it.
------------------------------
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 5114
***************************************