[25044] in Perl-Users-Digest
Perl-Users Digest, Issue: 7294 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 24 03:05:36 2004
Date: Sun, 24 Oct 2004 00:05:07 -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 Sun, 24 Oct 2004 Volume: 10 Number: 7294
Today's topics:
arrays of arrays question <nospam@nospam.com>
Re: arrays of arrays question cjs.lists@gmail.com
Re: arrays of arrays question cjs.lists@gmail.com
Fast random string generation <nospam@example.com>
Re: Fast random string generation <dave@nospam.net>
Re: Fast random string generation <notvalid@email.com>
Re: How to I get an user email address, if I know the d (Mav)
Is there any way to call a function w/in an RE <elduce@mailinator.com>
Re: list vs array <nospam@nospam.com>
Re: list vs array <nospam@nospam.com>
Re: list vs array <tadmc@augustmail.com>
Missing functions in h2ph converted headers (Chris Snell)
Re: open-perl-ide qustion <catcher@linuxmail.org>
Re: open-perl-ide qustion <nospam@nospam.com>
Re: open-perl-ide qustion <matthew.garrish@sympatico.ca>
Re: open-perl-ide qustion <wyzelli@yahoo.com>
Re: Optimize Perl.. <uri@stemsystems.com>
Re: perl optimazation guide/book <tadmc@augustmail.com>
Practical Extraction Recording Language <usa1@llenroc.ude.invalid>
Re: Practical Extraction Recording Language <uri@stemsystems.com>
Re: Practical Extraction Recording Language <notvalid@email.com>
What's the seed? <nospam@example.com>
Re: What's the seed? <usa1@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 24 Oct 2004 02:49:57 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: arrays of arrays question
Message-Id: <1098600637.568848@nntp.acecape.com>
ok, i have been thru perlfaq4 (i believe four) and my manuals aren't helping
me either, and/or it's just 3am...but need some help syntax wise.
in brief, i am going through my database afetr a query.
so what i am attempting to do, is to make an array of each array.
now below is what i have currently, but i can't figure out how to get OUT
each array. i tried a POP, but that didn't seem to give me an array i could
access (i.e. $row[0], etc).
now i do realize that \@row, means the address. so am curious if that means
that the reference to each row is cleared. but when i do the push without
the \@, and just @,
essentially @rows becomes a list....which is no longer a format that is easy
to work with.
could really use some help here,
thanks ahead
while (@row = $sth ->fetchrow_array)
{
my $trow = @row;
push @rows, \@row;
}
------------------------------
Date: 24 Oct 2004 00:01:56 -0700
From: cjs.lists@gmail.com
Subject: Re: arrays of arrays question
Message-Id: <1098601316.438593.187060@c13g2000cwb.googlegroups.com>
Save yourself the headache and try doing it this way:
# where 'key' is the table's primary key
$feched_data = $sth->fetchall_hashref('key');
foreach my $a_row (keys %{$fetched_data}) {
# your columns are available as keys
print "some_column :: $fetched_data->{$a_row}->{'some_column'} \n";
}
ok...it's late here and that's off the top of my head, so, apologies if
it doesn't work the way you want it
------------------------------
Date: 24 Oct 2004 00:02:54 -0700
From: cjs.lists@gmail.com
Subject: Re: arrays of arrays question
Message-Id: <1098601374.108624.128190@z14g2000cwz.googlegroups.com>
Save yourself the headache and try doing it this way:
# where 'key' is the table's primary key
$feched_data = $sth->fetchall_hashref('key');
foreach my $a_row (keys %{$fetched_data}) {
# your columns are available as keys
print "some_column :: $fetched_data->{$a_row}->{'some_column'} \n";
}
ok...it's late here and that's off the top of my head, so, apologies if
it doesn't work the way you want it.
chris
------------------------------
Date: Sun, 24 Oct 2004 11:38:30 +0800
From: Derek Fountain <nospam@example.com>
Subject: Fast random string generation
Message-Id: <417b232b$0$13761$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
I need to generate a string of random characters, say about 20,000
characters long. And I need to do it quickly! I tried the obvious:
for( my $i=0; $i<20000; $i++ ) {
$str .= chr(int(rand(256)));
}
which works, but I have a feeling there must be a faster way than doing
20,000 string concatenations...?
------------------------------
Date: Sat, 23 Oct 2004 21:41:46 -0700
From: "Dave Oswald" <dave@nospam.net>
Subject: Re: Fast random string generation
Message-Id: <ZIidnUWMrqpLr-bcRVn-tg@adelphia.com>
"Derek Fountain" wrote in message
> I need to generate a string of random characters, say about 20,000
> characters long. And I need to do it quickly! I tried the obvious:
>
> for( my $i=0; $i<20000; $i++ ) {
> $str .= chr(int(rand(256)));
> }
>
> which works, but I have a feeling there must be a faster way than doing
> 20,000 string concatenations...?
If speed actually matters (which it may not), you'll have to benchmark this
solution, comparing it to yours. They may turn out to be reasonably close
to each other in speed.
my $string = join '', map { chr int rand(256) } 1 .. 20_000;
Here's another solution that pre-generates the 'chr' possibilities, and
thus, MAY be a little more efficient.
my @characters = map { chr $_ } 0 .. 255;
my $string = join '', map { $characters[ rand 256 ] } 1 .. 20_000;
Dave
------------------------------
Date: Sun, 24 Oct 2004 06:37:26 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Fast random string generation
Message-Id: <G4Ied.34048$QJ3.25181@newssvr21.news.prodigy.com>
Derek Fountain wrote:
> I need to generate a string of random characters, say about 20,000
> characters long. And I need to do it quickly! I tried the obvious:
>
> for( my $i=0; $i<20000; $i++ ) {
> $str .= chr(int(rand(256)));
> }
>
> which works, but I have a feeling there must be a faster way than doing
> 20,000 string concatenations...?
I didn't benchmark, but I would guess it's faster to call chr() 256
times instead of 20000 times:
# untested code
my @list = map chr, 0 .. 256;
my $str = '';
$str .= $list[rand @list] for 1 .. 20_000;
--Ala
------------------------------
Date: 23 Oct 2004 23:39:34 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Re: How to I get an user email address, if I know the domain/username
Message-Id: <dfaafecd.0410232239.2f12a49f@posting.google.com>
Joe Smith <Joe.Smith@inwap.com> wrote in message news:<2Hqed.235042$wV.36303@attbi_s54>...
> Mav wrote:
>
> >>> Using Perl, Windows, if I know the person domain name(or the whole
> >>>user domain) and userid, like (google/foo). is that a way to return
> >>>that person the email address progrom? I am on the same domain.
> >
> > I want to write a perl script to figure out the email address.
>
> I'm in the NT domain as "\\camero\jms" but my e-mail address is
> "joe.smith@inwap.com". The latter is not obviously related to the
> former without doing an LDAP query.
> http://search.cpan.org/~gbarr/perl-ldap-0.3202/lib/Net/LDAP.pod
> -Joe
Thanks for your reply, if I know the username full
domain(something.smallworld.com), and username (foo).
Would it able to return the user full email address?
thanks,
Mav
------------------------------
Date: Sun, 24 Oct 2004 01:09:29 -0500
From: El Duce <elduce@mailinator.com>
Subject: Is there any way to call a function w/in an RE
Message-Id: <VKHed.2164$Z9.1112@fe25.usenetserver.com>
I would like to call a function w/in an RE. Say foo:
$x =~ s/abc(.*)def/foo($1)/g;
(I know that syntax doesn't work, but you hopefully get the idea).
Is there a way?
TIA,
El Duce
------------------------------
Date: Sat, 23 Oct 2004 21:09:10 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: list vs array
Message-Id: <1098580187.930636@nntp.acecape.com>
>>It is indeed rude to snip attributions when replying.
sorry, didn't realize you were the hall monitor assigned to police the
newgroup world. read both your posts. i took responsibility many posts ago
for my improper posting, and i try to reference old posts since then (with
one or two backsteps)....why not be a man, and take responsibility for your
rudeness.
>>On the other hand, given the number of
>>spelling errors per sentence you have been making, I am willing to bet you
>>are in quite a huff.
not a huff, can neither spell nor type....but i certainly enjoy the fact
that you (tad and sinan) can't seem to let this go. the chuckles you both
give me, lighten my mood and blood pressue....this thread would have been
down with days ago.
again, if am so rude, the easiest way to deal with me is to stop reading my
posts. whether in this thread or the new one i just started. you have my
word, i will never again open a post by either of you ever again....stop
fighting to have the last word.....be zen, or otherwise you only waste yours
and others time. yours is yours to do with as you wish, others, is not your
to decide....
> Yes, it is the principle. And the principle says, once you have been
> politely directed to a FAQ (see news:1098463265.457208@nntp.acecape.com),
> you go read it and the thread ends.
am curious what the FAQ says about uselessly keeping threads alive, i'll
have to look that up....
just to repeat, you have my word, will never open a post by either of you
again, in any thread....so if it will make you feel like a winner, keep
posting to (in reference) to me...since i won't open, i won't
reply....you'll at least get the last word that way and feel good about
yourselves....
be well...
------------------------------
Date: Sat, 23 Oct 2004 21:11:10 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: list vs array
Message-Id: <1098580307.925259@nntp.acecape.com>
> Really, the folks here are very helpful if you will help them help you.
oh, by all means, they are....it's like in any newgroup....you have the
helpers, and the posters....not always the same thing...if anythign you
taught me something about proper posting with this:
"BTW, I have my newsreader set to list posts by date. It makes it easier
to find the most recent posts. So I don't see posts in context. That is
why including some context is important."
made me realize tha the way i have my newsreader set isn't the rest of the
world....
thanks
------------------------------
Date: Sat, 23 Oct 2004 22:06:16 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: list vs array
Message-Id: <slrncnm718.2uj.tadmc@magna.augustmail.com>
Scott Bryce <sbryce@scottbryce.com> wrote:
> daniel kaplan wrote:
>
>>>Hey! Your feet stink!
>
>> i don't get, it, especially since that wasn't my post...
>
> No, MY feet stink. I told you that I have learned a lot from "rude"
> responses in this newsgroup, so Tad is being rude to me. I'm not sure
> what I'm supposed to learn this time.
To wash your feet?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 23 Oct 2004 23:10:54 -0700
From: cjs.lists@gmail.com (Chris Snell)
Subject: Missing functions in h2ph converted headers
Message-Id: <7ba66244.0410232210.20291b1e@posting.google.com>
Hi,
I need to access the getifaddrs() function, as defined in ifaddrs.h on
FreeBSD/OpenBSD/Mac OS X. I'm trying to read the kernel's traffic
counters for the machine's network interfaces. I ran h2ph on
/usr/include/ifaddrs.h but it did not make the getifaddrs() function
available to me. How can I make this system call from Perl?
Also, getifaddrs provides its data in a struct which contains other
structs. It's a pretty gnarly data structure. Supposing that I can
access this from Perl's syscall, how can I quickly determine the total
size of the idaddrs struct that getifaddrs returns so that I can
allocate space in my scalar for this data?
thanks,
Chris
PS- If anyone knows of a better way to access network interface
statistics (but doesn't involve calling netstat(1)), I'd love to hear
about it.
------------------------------
Date: Sat, 23 Oct 2004 21:24:38 -0400
From: "Robert" <catcher@linuxmail.org>
Subject: Re: open-perl-ide qustion
Message-Id: <98OdnTyahLzOmebcRVn-qA@adelphia.com>
"daniel kaplan" <nospam@nospam.com> wrote in message
news:1098579060.649973@nntp.acecape.com...
> can anyone recommend or NOT recommend this?
>
> i found it at faq.perl.org and just wondered if it was any good....
>
> thanks ahead
>
A couple of thoughts. One is that it hasn't moved since early 2003. The
other is that even for a single Perl script is creates a project file. I
think that is a waste. But your mileage may vary of course.
Robert
------------------------------
Date: Sat, 23 Oct 2004 21:38:33 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: open-perl-ide qustion
Message-Id: <1098581951.537700@nntp.acecape.com>
> A couple of thoughts. One is that it hasn't moved since early 2003.
my apologies, by moved, do you mean it hasn't been updated?
started playing with it, and it does seem simplistic. however i will say
this, i tried activestate's komodo. it was slow to load, slow to run, you
name it.
this one, open-perl-ide, seems semi-simplistic, but then again my PLs are as
well...and it loads quickly, without any delay.
but would love any recommendations that people might have in terms of IDE.
i far prefer it to command line world.
thanks agian
------------------------------
Date: Sat, 23 Oct 2004 22:36:10 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: open-perl-ide qustion
Message-Id: <oyEed.40526$J16.2367740@news20.bellglobal.com>
"daniel kaplan" <nospam@nospam.com> wrote in message
news:1098581951.537700@nntp.acecape.com...
>
> but would love any recommendations that people might have in terms of IDE.
> i far prefer it to command line world.
>
Beware the IDEs of March...
Matt
------------------------------
Date: Sun, 24 Oct 2004 03:49:44 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: open-perl-ide qustion
Message-Id: <sDFed.37059$5O5.2910@news-server.bigpond.net.au>
"daniel kaplan" <nospam@nospam.com> wrote in message
news:1098581951.537700@nntp.acecape.com...
>> A couple of thoughts. One is that it hasn't moved since early 2003.
>
> started playing with it, and it does seem simplistic. however i will say
> this, i tried activestate's komodo. it was slow to load, slow to run, you
> name it.
I find the same for Komodo, 2+ mins to start (on a P4 2.8 Ghz 512 Mb RAM)
> this one, open-perl-ide, seems semi-simplistic, but then again my PLs are
> as
> well...and it loads quickly, without any delay.
Haven't tried it so can't comment
> but would love any recommendations that people might have in terms of IDE.
> i far prefer it to command line world.
I have been very happy with PerlBuilder 2.0 Pro, (though it has some small
bugs / quirks / misfeatures) and some other people hate it, I find the way
it's debugger works is very intuitive and simple (hover mouse to inspect
variable contents) plus many other features.
You will get some comments about numerous text editors, some with Perl
syntax highlighting and some without. I personally find the syntax
highlighting makes a huge improvement to productivity, and PB 2.0 does that
very well. It has several other features I use a lot:- sub-routine
navigator, cgi-wizard (which uses cgi.pm though in a slightly
naive/automated way) and the ability to do interactive I/O which are all
very good.
Take it for a test fun ( Per programming is fun... :))
--
Wyzelli
{{${^_sub}=sub{scalar reverse shift}}{$_={${^_reverse}=>
{${^_scalar}=>{${^_shift}=>{${^_sub}=>{${^_print}=>{}}}}}}
}{s{.*}{rekcaH lreP rehtona tsuJ}}{print("@{[&${^_sub}($_)]}")}}
------------------------------
Date: Sun, 24 Oct 2004 05:19:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Optimize Perl..
Message-Id: <x7acucd78q.fsf@mail.sysarch.com>
>>>>> "MP" == Matija Papec <perl@my-header.org> writes:
MP> http://www-106.ibm.com/developerworks/library/l-optperl.html?ca=dgr-lnxw06OptPerl
MP> Usually they have good articles but this one isn't nearly there,
MP> and I doubt that author is just making jokes in it?
here is the feedback i sent him:
so many misconceptions about perl that i can't even start. and
he misses so many ways to optimize perl as well.
no mention of the Benchmark.pm module.
perl bytecode is generally useless and doesn't give much speedup
choosing a better algorithm and/or data structure is the best
way to optimize code in any language. if you think perl 's speed
is the problem then you either chose the wrong language or don't
know how to code perl efficiently. examining bytecode is silly
in this context. it still won't show you which ops are the
bottlenecks.
the speed difference between single and double quoted strings is
negligible. try a benchmark yourself. double quoted strings are
converted to a join of the string parts at compile time so there
is no runtime loss for simple strings.
want more? write to me at uri@sysarch.com.
let's see if i get any response.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sat, 23 Oct 2004 22:10:04 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl optimazation guide/book
Message-Id: <slrncnm78c.2uj.tadmc@magna.augustmail.com>
buildmorelines <bulk88@hotmail.com> wrote:
> Are there any books or guide to Perl function and operator and syntax
> (not algorithem) optimzation? like a guide that says what function or
> way of doing something is faster than another.
>
> Two of them I discovered were scalar(@array) is faster than $#array,
They do not do the same thing.
> and pop(@array) is faster than $array[-1].
They do not do the same thing either.
> Are there any more of those
> kinds of optimzations?
You mean the kind that don't do the same thing? :-)
> The fasterness was determined by running a perl script
You can use the Benchmark module for benchmarking, but when you do,
you should probably benchmark code that does the same thing.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 Oct 2004 05:25:36 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Practical Extraction Recording Language
Message-Id: <Xns958CE837A2D0asu1cornelledu@132.236.56.8>
Just for laughs:
http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
Sinan.
------------------------------
Date: Sun, 24 Oct 2004 06:12:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Practical Extraction Recording Language
Message-Id: <x7wtxgbq7q.fsf@mail.sysarch.com>
>>>>> "ASU" == A Sinan Unur <usa1@llenroc.ude.invalid> writes:
ASU> Just for laughs:
ASU> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
The following elements are symbols and special variables that
are very important in Perl. You should know and understand the
function of these. They are special and have been set aside for
specific use by the program.
#! - This symbol tells the kernel what program is
interpreting the script. It will be followed by the path
name. In our case, the first line of every Perl script will
be #!/usr/bin/perl.
hahahhahah!!!! what a wacked out explanation of #!. first he says it is
a perl symbol and then he says it is used by the kernel.
; - The semicolon is the part of Perl language that terminates a
statement. A perl statement is an expression or series of
expressions that will not be executed without the semicolon.
huh??? perl -e 'print "the author is a doofus\n"'
don't see no ; there!
Chop or Chomp ? The chop and chomp function take off the last
character of a string or variable. For our intents and purposes,
they can be used interchangeably. They are usually used to take
off the return of a standard input (from the keyboard) so that
it is not read as part of a variable.
this is getting worse and worse. where do these perl tutorial authors
get their nonsense from? it just supports my creed that almost all perl
web tutes are crap. i can still only think of a handful (from dozens!)
that are decent.
Defined Expression ? The defined function returns a Boolean
value of 1 when an expression has a real value and 0 when it
does not. It allows you to check the validity of variables. This
is useful for understanding where a fatal error is coming from.
????? if it is a fatal error, how can defined even get called?
Die ? The die function is used if a call to open function
fails. For instance, if the user types the wrong file name for
the data file that is being filtered, a die function can be used
to stop the program from progressing. It exits the Perl script
with the value of $! and prints a message to the STDERR.
hmm, die can only be used with open?
Evaluate ? The eval function allows the user to check for errors
in the Perl script. It evaluates an expression and the errors
are returned to the $@ variable.
hmm, conflating eval string vs eval block. i wouldn't have expected
anything else from this page.
Join ? The join function converts a LIST of variables to an
array separated by a delimiter specified by EXPR.
that is a winner!
plenty of more poorly worded stuff. then i find this gem:
Quotes effect almost everything you do in Perl and are used
especially when printing a string of words. The three kinds of
quotes are single (' '), double (" "), or backslashes (\ \).
backslashes are quotes? and in pairs? can someone point me to the docs
for this? more on this:
Backslashes can be used only to quote a single character. A
single backslash can be used to tell the program not to read a
special Perl character as such. For instance, if you want to use
a dollar sign in your output, you would put \$ in your script so
that Perl would not think you were introducing a variable.
wow. print \$foo ;
there is no mention of context anywhere especially for those funcs and
ops where it matters (e.g. check out reverse)
These terms along and much of the material in this Perl Tutorial
can be found in the book Perl by Example written by Ellie
Quigley (1995). I have chosen the terms applicable to scientific
data filtering using Perl in an attempt to facilitate
learning. This tutorial was written for the participants of the
National Science Foundation grant REVITALISE for educational
purposes only.
that is an infamously bad perl book and amazingly out of date. so he
plagiarized a bad book and was paid for it?
Links:
ActiveState - This link will take you to ActiveState's Perl
page. Here you can download the correct version of Perl for
your machine as well as find a plethora of other useful
information.
so activestate is the center of the perl universe. that is the only link
in that section. and consider that the #! crap is unix only but he
refers to a winblows oriented perl (yes, i know they have unix versions
but who uses those?).
it opens with:
Lindsay Husted, presently an undergraduate at the University of
North Carolina and an NSF appointee, built this site.
the last modified time is:
06/16/04 15:20:44
this page is mind boggling. if someone can find an email address, feel
free to forward my critique.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 24 Oct 2004 06:30:31 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Practical Extraction Recording Language
Message-Id: <a_Hed.34045$QJ3.25896@newssvr21.news.prodigy.com>
Uri Guttman wrote:
>>>>>>"ASU" == A Sinan Unur <usa1@llenroc.ude.invalid> writes:
>
>
> ASU> Just for laughs:
> ASU> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
[snip valid critique]
> this page is mind boggling. if someone can find an email address, feel
> free to forward my critique.
I'm totally surprised you actually went through the whole page! I just
couldn't go on after the first few paragraphs. Things like this should
be illegal!
DIRHANDLE - This is the name of the directory.
huh?
KEY - The numeric identification assigned to each element of an
associative array (usually starts at one and counts up).
VALUE - The non-numeric identification assigned to each element of
an associative array.
So keys have to be numeric and values have to be non-numeric? Later on,
he (fortunately) contradicts himself:
ASSOC - A variable that contains a list of values that is indexed by
a string. It is preceded by the % symbol. Its individual elements are
scalar.
STRING - Non-numerical variable (perhaps a list of words)
Why non-numeric?
I just couldn't go on any further. The worst Perl tutorial I've seen by far.
--Ala
------------------------------
Date: Sun, 24 Oct 2004 11:09:46 +0800
From: Derek Fountain <nospam@example.com>
Subject: What's the seed?
Message-Id: <417b1c6f$0$13760$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
In any recent version of Perl, the seed for the random number generator is
set at the first time rand() is called. Can I find out what that seed is so
I can subsequently reproduce the random sequence?
At present I'm setting my own seed using "time ^ ($$ + ($$ << 15))", but my
program is being run repeatedly over and over, and only takes a fraction of
a second to do its job. That means time is often the same for several runs,
and $$ tends to go up in small, sometimes single, steps. I have my
suspicions about the quality of my seed!
------------------------------
Date: 24 Oct 2004 05:21:13 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: What's the seed?
Message-Id: <Xns958CDC53CA5asu1cornelledu@132.236.56.8>
Derek Fountain <nospam@example.com> wrote in
news:417b1c6f$0$13760$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
> In any recent version of Perl, the seed for the random number
> generator is set at the first time rand() is called. Can I find out
> what that seed is so I can subsequently reproduce the random sequence?
It might have been nice to srand return the current seed for this purpose,
but given that the standard C srand function also does not return the seed,
I have a feeling there is a good reason for it.
What I have always done is to find a good way of generating seeds and then
save them.
> At present I'm setting my own seed using "time ^ ($$ + ($$ << 15))",
> but my program is being run repeatedly over and over, and only takes a
> fraction of a second to do its job. That means time is often the same
> for several runs, and $$ tends to go up in small, sometimes single,
> steps. I have my suspicions about the quality of my seed!
I am going to suggest using the Math::Random package.
#! perl
use strict;
use warnings;
use Math::Random;
my $s = [ random_get_seed() ];
my @series;
for my $i ( 0 .. 1 ) {
$series[$i] = [ random_uniform(10, 0, 1) ];
random_set_seed(@$s);
}
use Data::Dumper;
print Dumper \@series;
__END__
Sinan
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7294
***************************************