You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by David Jacobs <dj...@cheetahmail.com> on 2002/04/30 21:38:42 UTC
Cheap and unique
I'm converting a few CGI scripts that used the PID as a cyclical unique
number (in concert with TIMESTAMP - so it was TIMESTAMP.PID).
Our goal is to find a replacement function that is extremely cheap
(cheaper than say, random(1000000)) and will never repeat. Any ideas?
Has anyone else faced this problem?
tia
David
Re: Cheap and unique
Posted by Steve Piner <st...@marketview.co.nz>.
David Jacobs wrote:
>
> I'm converting a few CGI scripts that used the PID as a cyclical unique
> number (in concert with TIMESTAMP - so it was TIMESTAMP.PID).
>
> Our goal is to find a replacement function that is extremely cheap
> (cheaper than say, random(1000000)) and will never repeat. Any ideas?
> Has anyone else faced this problem?
>
> tia
> David
I'm just curious - what's wrong with the function you're already using?
Steve
--
Steve Piner
Web Applications Developer
Marketview Limited
http://www.marketview.co.nz
Re: Cheap and unique
Posted by Perrin Harkins <pe...@elem.com>.
David Jacobs wrote:
> I'm converting a few CGI scripts that used the PID as a cyclical unique
> number (in concert with TIMESTAMP - so it was TIMESTAMP.PID).
>
> Our goal is to find a replacement function that is extremely cheap
> (cheaper than say, random(1000000)) and will never repeat. Any ideas?
Yes, mod_unique_id will do that, as will Sys::UniqueID and Data::UUID on
CPAN. Of course that random function is probably very lightweight, but
it's not actually unique.
- Perrin
RE: Cheap and unique
Posted by Andrew Ho <an...@tellme.com>.
Hello,
OCNS>You could try -> Math::TrulyRandom CPAN module.....
Perrin's comments still apply. There is no guarantee that a random number
generator of any type (truly random or otherwise) will return unique
values. In fact, one would fully expect repetition after some amount of
time.
Humbly,
Andrew
----------------------------------------------------------------------
Andrew Ho http://www.tellme.com/ andrew@tellme.com
Engineer info@tellme.com Voice 650-930-9062
Tellme Networks, Inc. 1-800-555-TELL Fax 650-930-9101
----------------------------------------------------------------------
RE: Cheap and unique
Posted by OCNS Consulting <co...@ocns.com>.
You could try -> Math::TrulyRandom CPAN module.....
RB
-----Original Message-----
From: Perrin Harkins [mailto:perrin@elem.com]
Sent: Tuesday, April 30, 2002 4:08 PM
To: OCNS Consulting
Cc: David Jacobs; modperl@apache.org
Subject: Re: Cheap and unique
OCNS Consulting wrote:
> Check your "Programming in PERL" book. Specifically, the "srand" function.
'random' ne 'unique'
A random function could return the same number 10 times in a row. It's
very unlikely, but it could happen. That's the definition of random.
- Perrin
Re: Cheap and unique
Posted by Perrin Harkins <pe...@elem.com>.
OCNS Consulting wrote:
> Check your "Programming in PERL" book. Specifically, the "srand" function.
'random' ne 'unique'
A random function could return the same number 10 times in a row. It's
very unlikely, but it could happen. That's the definition of random.
- Perrin
RES: Perl Callbacks not working
Posted by Vitor <vs...@uol.com.br>.
Mark,
First, thanks for you reply.
I know that Acmemail runs fine under mod_perl.
I think the reason for this is that their script runs as an common CGI, and
not as a cached bytecode.
About you second suggestion, i just changed the values of login and password
that i use.
Best Regards,
Vitor
-----Mensagem original-----
De: Mark Fowler [mailto:mark@astray.com]Em nome de Mark Fowler
Enviada em: quarta-feira, 1 de maio de 2002 06:27
Para: Vitor
Cc: modperl@apache.org
Assunto: Re: Perl Callbacks not working
On Tue, 30 Apr 2002, Vitor wrote:
> use strict;
> use Mail::CClient qw(set_callback);
> set_callback (login=> sub { return ("login","password"); } )
I don't see any reason why this shouldn't work. Acmemail (which runs fine
under mod_perl) uses Mail::CClient with callbacks without problem.
> I think this is related with the cacching feature of mod_perl that need to
> be disabled for pages that uses these callbacks.
What are you expecting to happen here? When Mail::CClient needs a login
it will call the anonymous subroutine passed on login which will simply
return the two values "login" and "password". These need to be set to the
login and password of your POP/IMAP/Whatever account.
You could be getting things confused with closures here, it's reasonably
easy to do.
sub init
{
my $login,$password;
set_callback (login=> sub { return ($login,$password); } )
}
Will not login no matter what you set $login or $password to be later as
the anonymous subroutine will be bound to the particular $login and
$password created in init.
Hope this is helpful (and the problem isn't more serious)
Mark.
--
s'' Mark Fowler London.pm Bath.pm
http://www.twoshortplanks.com/ mark@twoshortplanks.com
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}
Re: Perl Callbacks not working
Posted by Mark Fowler <ma...@twoshortplanks.com>.
On Tue, 30 Apr 2002, Vitor wrote:
> use strict;
> use Mail::CClient qw(set_callback);
> set_callback (login=> sub { return ("login","password"); } )
I don't see any reason why this shouldn't work. Acmemail (which runs fine
under mod_perl) uses Mail::CClient with callbacks without problem.
> I think this is related with the cacching feature of mod_perl that need to
> be disabled for pages that uses these callbacks.
What are you expecting to happen here? When Mail::CClient needs a login
it will call the anonymous subroutine passed on login which will simply
return the two values "login" and "password". These need to be set to the
login and password of your POP/IMAP/Whatever account.
You could be getting things confused with closures here, it's reasonably
easy to do.
sub init
{
my $login,$password;
set_callback (login=> sub { return ($login,$password); } )
}
Will not login no matter what you set $login or $password to be later as
the anonymous subroutine will be bound to the particular $login and
$password created in init.
Hope this is helpful (and the problem isn't more serious)
Mark.
--
s'' Mark Fowler London.pm Bath.pm
http://www.twoshortplanks.com/ mark@twoshortplanks.com
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}
Perl Callbacks not working
Posted by Vitor <vs...@uol.com.br>.
Hello,
I am trying to use a Perl Module that is an interface to a C Library.
These module use some "callbacks" , like these perl Code:
use strict;
use Mail::CClient qw(set_callback);
set_callback (login=> sub { return ("login","password"); } )
I think this is related with the cacching feature of mod_perl that need to
be disabled for pages that uses these callbacks.
Thanks in advance,
Vitor
RE: Cheap and unique
Posted by OCNS Consulting <co...@ocns.com>.
Check your "Programming in PERL" book. Specifically, the "srand" function.
RB
-----Original Message-----
From: David Jacobs [mailto:djacobs@cheetahmail.com]
Sent: Tuesday, April 30, 2002 3:39 PM
To: modperl@apache.org
Subject: Cheap and unique
I'm converting a few CGI scripts that used the PID as a cyclical unique
number (in concert with TIMESTAMP - so it was TIMESTAMP.PID).
Our goal is to find a replacement function that is extremely cheap
(cheaper than say, random(1000000)) and will never repeat. Any ideas?
Has anyone else faced this problem?
tia
David
Re: Cheap and unique
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,
On Tue, 30 Apr 2002, David Jacobs wrote:
> I'm converting a few CGI scripts that used the PID as a cyclical unique
> number (in concert with TIMESTAMP - so it was TIMESTAMP.PID).
>
> Our goal is to find a replacement function that is extremely cheap
> (cheaper than say, random(1000000)) and will never repeat. Any ideas?
Have a look at Time::HiRes?
73,
Ged.