[18085] in Perl-Users-Digest
Perl-Users Digest, Issue: 245 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 8 14:16:06 2001
Date: Thu, 8 Feb 2001 11:15:36 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981659735-v10-i245@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 8 Feb 2001 Volume: 10 Number: 245
Today's topics:
non repeating random numbers <jason@cyborgworkshop.com>
Re: non repeating random numbers <dpc29@sheetmusic.org.uk>
Re: non repeating random numbers <wuerz@yahoo.com>
Re: non repeating random numbers <jason@cyborgworkshop.com>
Re: non repeating random numbers <wuerz@yahoo.com>
Re: non repeating random numbers mike_solomon@lineone.net
Re: non repeating random numbers <jason@cyborgworkshop.com>
Re: non repeating random numbers <godzilla@stomp.stomp.tokyo>
Re: non repeating random numbers <jason@cyborgworkshop.com>
Re: non repeating random numbers <wuerz@yahoo.com>
Re: non repeating random numbers <dpc29@sheetmusic.org.uk>
Re: non repeating random numbers <jason@cyborgworkshop.com>
Re: Package Positioning nobull@mail.com
Re: perl -V error edis9@my-deja.com
Re: Perl DBI newbie question ... <fty@mediapulse.com>
Re: Place an array item in a specific place. (LK)
Please help, my WIN32::API script cant run after upgrad <wstsoi@hongkong.com>
Problems with find.pl and winnt paulvanderheijden@my-deja.com
setting degree of parallelism jrpink@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 8 Feb 2001 09:32:33 -0600
From: "Jason from The Workshop" <jason@cyborgworkshop.com>
Subject: non repeating random numbers
Message-Id: <t85f45e7oans1c@news.supernews.com>
I have need to generate a random number between 1 and 50 without using a
number that has already been generated. Its for an online test for our
employees consisting of 50 questions that all need to be asked, but I want
to make sure that they are random and of course no question is asked twice.
I have consulted my perl cookbook, pretty much all of my perl books for that
matter, searched Deja, gone through the news group and haven't found a
solution. What I have thus far is to just generate my random number using
RAND, then stuff my list of already used numbers into an array, step through
the array looking for $rand, and if $rand is found, regenerate a new $rand
and do it again. Problem is that as soon as it regenerates a new random
number, it seems to just go from where it left off and does look back at the
start of the list so I'm still getting duplicates. I'm sure the code isn't
the greatest as I'm still in amateur land, but any help would be very
appreciated.
$rand = int(rand(49))+1);
$asked = "1:2:3:4:";
sub duplicate {
@sked = split(/:/,$asked) ;
foreach $num(@sked) {
while ($rand >= 50) {
&all_done;
} else {
$rand++;
&duplicate;
}
}
}
--
Jason
www.cyborgworkshop.com
...and the geek shall inherit the earth...
------------------------------
Date: Thu, 8 Feb 2001 16:27:28 +0000
From: David Chan <dpc29@sheetmusic.org.uk>
Subject: Re: non repeating random numbers
Message-Id: <Pine.SOL.4.21.0102081622290.16020-100000@yellow.csi.cam.ac.uk>
On Thu, 8 Feb 2001, Jason from The Workshop wrote:
> I have need to generate a random number between 1 and 50 without using a
> number that has already been generated.
Apologies, I haven't really looked at the code you posted, but here's a
sub I used myself for a similar purpose; it returns the first n integers
in random order. Note that it would be silly to use this method for big
numbers, but 50 is ok.
============================================================
sub randlist { # returns a list (1..$n), sorted randomly
my $n = shift or die "need a positive integer argument";
my @shuffle = ();
for (1..$n) {
my $try = 1 + int rand $n;
while(grep /^$try$/, @shuffle) {
$try = 1 + int rand $n;
}
push @shuffle, $try;
}
@shuffle;
}
============================================================
To use this, you want something like:
foreach my $n (randlist(50)) {
ask_question($n);
}
Hope this is some use,
Regards,
--
David
------------------------------
Date: Thu, 08 Feb 2001 17:42:24 +0100
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: non repeating random numbers
Message-Id: <080220011742247770%wuerz@yahoo.com>
In article <t85f45e7oans1c@news.supernews.com>, "Jason from The
Workshop" <jason@cyborgworkshop.com> wrote:
> I have need to generate a random number between 1 and 50 without using a
> number that has already been generated. Its for an online test for our
> employees consisting of 50 questions that all need to be asked, but I want
> to make sure that they are random and of course no question is asked twice.
You could make an array that contains the questions (or their ref.
numbers, or something else suitable) and then shuffle it before each
time the questions are presented. Then work through that sequentially.
That way, since each (reference to a) question is in the array only
once, no duplicates can occur.
perlfaq4: "How do I shuffle an array randomly?"
(been asked and answered within the last week, deja is also yor frend.)
-mona
------------------------------
Date: Thu, 8 Feb 2001 10:57:11 -0600
From: "Jason from The Workshop" <jason@cyborgworkshop.com>
Subject: Re: non repeating random numbers
Message-Id: <t85k2rmci83rbe@news.supernews.com>
Thank you very much Mona and Dave for your responses. The problem that Im
running into is not the randomizing of the array, that works pretty well.
What seems to be happening is that I have an array that has only the
reference number for the questions that the user has been asked allready.
So for example, I have been asked questions 1,2,3 and 4. Where I run into
trouble is when I generate my random number, lets say 3, and then look in
that array to make sure that I havent allready asked them that question.
It seems to loop through 1 and 2 ok, hits three and regens a new random
number, like its supposed to, but lets say it then generates a 1. It seems
like the rest of the routine continues looking for a duplicate, but starts
at 3. 2 doesnt match 3 or 4, so it is marked as an ok question, when in
fact it has been asked before.
Any ideas?
--
Jason
www.cyborgworkshop.com
...and the geek shall inherit the earth...
------------------------------
Date: Thu, 08 Feb 2001 18:00:37 +0100
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: non repeating random numbers
Message-Id: <080220011800373563%wuerz@yahoo.com>
In article <t85k2rmci83rbe@news.supernews.com>, "Jason from The
Workshop" <jason@cyborgworkshop.com> wrote:
> Any ideas?
Yes. Please post (the relevant parts of) your code. I'm embarrassed to
say that I didn't understand a word of your explanation. Looking at the
actual code would probably clear things up.
-mona
------------------------------
Date: Thu, 08 Feb 2001 17:01:32 GMT
From: mike_solomon@lineone.net
Subject: Re: non repeating random numbers
Message-Id: <95ujd5$3e$1@nnrp1.deja.com>
In article <t85f45e7oans1c@news.supernews.com>,
"Jason from The Workshop" <jason@cyborgworkshop.com> wrote:
> I have need to generate a random number between 1 and 50 without
using a
> number that has already been generated. Its for an online test for
our
> employees consisting of 50 questions that all need to be asked, but I
want
> to make sure that they are random and of course no question is asked
twice.
> I have consulted my perl cookbook, pretty much all of my perl books
for that
> matter, searched Deja, gone through the news group and haven't found a
> solution. What I have thus far is to just generate my random number
using
> RAND, then stuff my list of already used numbers into an array, step
through
> the array looking for $rand, and if $rand is found, regenerate a new
$rand
> and do it again. Problem is that as soon as it regenerates a new
random
> number, it seems to just go from where it left off and does look back
at the
> start of the list so I'm still getting duplicates. I'm sure the code
isn't
> the greatest as I'm still in amateur land, but any help would be very
> appreciated.
>
> $rand = int(rand(49))+1);
> $asked = "1:2:3:4:";
> sub duplicate {
> @sked = split(/:/,$asked) ;
> foreach $num(@sked) {
> while ($rand >= 50) {
> &all_done;
> } else {
> $rand++;
> &duplicate;
> }
> }
> }
>
> --
>
> Jason
> www.cyborgworkshop.com
> ...and the geek shall inherit the earth...
>
>
I think this should acheive what you want
my $count = 1;
my @rand = ();
while ( $count <= 50 ) {
while ( grep /^${rand}$/, @rand ) {
$rand = int(rand(50)+1);
}
print "$count $rand\n";
push @rand,$rand;
$count++;
}
Regards
Mike Solomon
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 8 Feb 2001 11:14:05 -0600
From: "Jason from The Workshop" <jason@cyborgworkshop.com>
Subject: Re: non repeating random numbers
Message-Id: <t85l2m6joltka9@news.supernews.com>
> Yes. Please post (the relevant parts of) your code. I'm embarrassed to
> say that I didn't understand a word of your explanation. Looking at the
> actual code would probably clear things up.
The embarrassment should be mine for not being able to adequately explain my
problem. The code that I'm using to generate my random number and create
the array of already asked questions is in my original post, but I will
repost it here. Again, I apologize if the code is garbage, but I'm still
pretty new.
#Omitting the DBI and CGI stuff, here is my rand number and already asked
list
$rand = int(rand(49))+1);
$asked = "1:2:3:4:";
#I'm hoping that this subroutine will step through each element in the
already asked
#list and compare them to the random number that is generated. If that
random
#number is greater then 50, then we have exhausted all of the questions and
can
#run the scoring subroutine. Otherwise, add 1 to the random number and
step
#again through the already asked array.
sub duplicate {
@sked = split(/:/,$asked) ;
foreach $num(@sked) {
while ($rand >= 50) {
&all_done;
} else {
$rand++;
&duplicate;
}
}
}
As I mentioned, the random number works great, the already asked array seems
fine and
has all of its elements. The problem that I run into is that after a
duplicate has been found
and a new random number has been generated, the subroutine just seems to
start where it
left off when it found the match instead of starting at the beginning of the
array. So I end up with something like an already asked list of
1:2:3:4:5:6:7:8:, an initial random number of 4. The subroutine sees that 4
is in the already asked list, so it regenerates a new random number, lets
say 1, and continues looking for a match. It doesn't find 1 in the numbers
4-8, but never seems to look back at 1-4. I want my routine to look at 1-8
every time, even when it has to regen a new number.
Thank you for your help and patience.
--
Jason
www.cyborgworkshop.com
...and the geek shall inherit the earth...
------------------------------
Date: Thu, 08 Feb 2001 09:28:05 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: non repeating random numbers
Message-Id: <3A82D725.12462F0A@stomp.stomp.tokyo>
Jason wrote:
(this article)
> Thank you very much Mona and Dave for your responses. The problem
> that Im running into is not the randomizing of the array, that
> works pretty well. What seems to be happening is that I have an
> array that ...
(snipped)
Are you looking for help or looking to annoy people
with argumentative illogical responses? Clearly your
interests lie in the latter based on this article and,
your subsequent articles.
You have every right to approach your personal problem
in the most illogical bird brained way possible. However,
I question if you have a right to consistently annoy
people here, especially those who are sincerely trying
to help others. Have you realistically assessed your
societal based ethics lately?
**
(previous article)
> I have need to generate a random number between 1 and 50 without using a
> number that has already been generated. Its for an online test for our
> employees consisting of 50 questions that all need to be asked, but I want
> to make sure that they are random and of course no question is asked twice.
> I have consulted my perl cookbook...
(snipped)
This publisher, O'Reilly, and its employees should
be lined up for old fashioned stern English teacher
swats with a paddle, then made to write one-thousand
times on a chalkboard,
"We will produce professionally edited and published books."
Your Perl Cookbook is amongst the worst of books on Perl.
Trust nothing you read in this book; it is riddled with
errors throughout its content and index.
However, you can find information on a Fisher Yates shuffle
on page 121 and 122. You may also find information here:
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4.html#How_do_I_shuffle_an_array_random
This link above should be one long line, watch the word-wrap.
Typical for Perl documentation, you will find examples but
will not find any discussion of how this method works. I am
quite convinced those whose write Perl documentation don't
have a clue how 'stuff' works, they only know it does.
I am equally convinced those who write Perl documentation,
have never taken a class in English. Personally, I suspect
they learned how to write by reading stall walls in a
gas station men's restroom.
You might find randomizing an array of numbers, one through
fifty, inclusive, to be an easier solution for your problem.
Fisher-Yates is a method of marching through an array, swapping
element positions based on comparison of incoming elements
and a randomized control. This will produce a randomized
'list' of numbers upon which you can base your question
order to be asked.
A test script based on the Fisher Yates shuffle is below
my signature.
Godzilla!
--
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
@Array = (1 .. 10);
&Randomize (\@Array);
sub Randomize
{
$random = shift;
for ($iterate = @$random; --$iterate; )
{
$control = int rand ($iterate + 1);
if ($iterate == $control)
{ next; }
@$random[$iterate, $control] = @$random[$control, $iterate];
}
}
print "Contents Of Array:\n @Array";
exit;
PRINTED RESULTS:
________________
Contents Of Array:
6 8 5 4 10 7 1 3 2 9
------------------------------
Date: Thu, 8 Feb 2001 11:48:22 -0600
From: "Jason from The Workshop" <jason@cyborgworkshop.com>
Subject: Re: non repeating random numbers
Message-Id: <t85n31jh8r400d@news.supernews.com>
> Are you looking for help or looking to annoy people
> with argumentative illogical responses? Clearly your
> interests lie in the latter based on this article and,
> your subsequent articles.
<snip>
I'm sorry that I offended you, although I don't see how I did other then
asking for help. It appears though that I have not explained myself
properly, or perhaps I'm just not understanding the replies that I'm
getting. I'm not having a problem randomizing an array, and in fact,
randomizing an array isn't really what I'm going for here. I just want to
keep duplicates out of an array that are being generated by something else.
The array isn't being read from, other then to compare the current value of
the number that I'm wanting to use to the values that are in the array. The
array is just for already asked questions, the random number is for the
next question to be asked. If the array of already asked questions contains
my next question to be asked, I want to regen a new next question to be
asked. That's all working well. What's not working well is that the new next
question to be asked is then not checking the full asked questions array,
but is instead just starting at the point where it left off, thus missing a
lot of already asked questions and creating duplicates.
<snip>
> print "Content-type: text/plain\n\n";
>
> @Array = (1 .. 10);
<snip>
Again, thank you for the example, but this is randomizing an array. Not
preventing duplicates in an array.
I apologize if I'm coming off as a troll. That was certainly not my
intention. As I listed in my original post, I checked all the resources I
knew to check, Deja, all my perl books and was not able to find anything
that addressed this problem. I apologize again, but please don't read any
malice into my query. I'm just asking for some help.
--
Jason
www.cyborgworkshop.com
...and the geek shall inherit the earth...
------------------------------
Date: Thu, 08 Feb 2001 18:52:52 +0100
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: non repeating random numbers
Message-Id: <080220011852522251%wuerz@yahoo.com>
In article <t85l2m6joltka9@news.supernews.com>, "Jason from The
Workshop" <jason@cyborgworkshop.com> wrote:
[snip]
Alright, what I was suggesting earlier (and someone else, too) was to
approach the problem differently. I think, your approach (judging from
your code) is rather convoluted. This is also reflected in the
difficulty explaining it (no offense). (In case I misunderstood your
intentions, I apologize.)
Simpler would be the following. The actual code I'm about to suggest is
probably very inelegant, but it shows the principle.
Suppose the questions you're going to present are contained in
my @questions;
(I didn't see that part in your code, so I'll assume my own name.)
Suppose then, that
$questions[1] = 'Do you like dogs?';
$questions[2] = 'Are monkeys funny?';
$questions[3] = 'How about bananas?';
$questions[4] = 'Don't you agree that recursion is overrated?';
...
(etc.)
As I understand it, you would like to ask these questions in a random
order.
First generate an array with 50 numbers, randomly placed in it. This is
what the perlfaq4 reference was for.
Let's call that array @arr.
srand;
my @arr = ();
my @temp = 1..50;
while (@temp) {
push(@arr, splice(@temp, rand @temp, 1));
}
(yes, this code is pasted directly from the faq, numbers adjusted)
Once you've done that, the array will look something like:
($arr[1] == 10), ($arr[2] == 47), etc. (example)
Now, just go and work down the original @questions array like this:
foreach (1..50) {
print $questions[$arr[$_]]."\n";
# or do whatever else you need in place of 'print'
}
...and you're done. No complicated keeping track of what's already been
asked. Just repeat the shuffling step as needed.
Did that help with your problem?
-mona
------------------------------
Date: Thu, 8 Feb 2001 18:29:50 +0000
From: David Chan <dpc29@sheetmusic.org.uk>
Subject: Re: non repeating random numbers
Message-Id: <Pine.SOL.4.21.0102081815530.16703-100000@yellow.csi.cam.ac.uk>
On Thu, 8 Feb 2001, Jason from The Workshop wrote:
> Thank you very much Mona and Dave for your responses. The problem that Im
> running into is not the randomizing of the array, that works pretty well.
> What seems to be happening is that I have an array that has only the
> reference number for the questions that the user has been asked allready.
Hi Jason,
I hadn't realised exactly what you were asking when I posted my original
response. I can tell you where your problem lies (although, as others
have commented, it might be better for you to use one of the methods that
have been suggested, since they may be easier to follow).
$rand = int(rand(49))+1); # $rand is a global variable
$asked = "1:2:3:4:";
sub duplicate {
@sked = split(/:/,$asked) ;
foreach $num(@sked) {
while ($rand >= 50) { # $rand is still a global variable
&all_done;
} else {
$rand++; # $rand is still a global variable
&duplicate;
}
}
}
So when you call duplicate() the second time, it's not working on a fresh
variable called $rand, but on the same copy as everywhere else in the
script. I.e. if "$rand++" increased $rand to 5, then when you invoke
another instance of "&duplicate", it will start with $rand equal to 5.
You can stop the $rand variable being global by declaring it locally using
my() (see man perlfunc). However, due to other quirks of your script as
it stands (e.g. AFAICS you only pick a random number once), I'd strongly
advise you to use one of the solutions which have been outlined in this
thread. It will save you a lot of debugging effort and probably be more
enlightening.
David
--
Lbh unir gbb zhpu serr gvzr.
------------------------------
Date: Thu, 8 Feb 2001 12:59:36 -0600
From: "Jason from The Workshop" <jason@cyborgworkshop.com>
Subject: Re: non repeating random numbers
Message-Id: <t85r8bdh2t8v2b@news.supernews.com>
Thank you everyone for your responses. I have a great starting point now,
and its obvious that I need to rethink how Im approaching this. Thank you
all again.
--
Jason
www.cyborgworkshop.com
...and the geek shall inherit the earth...
------------------------------
Date: 08 Feb 2001 17:40:50 +0000
From: nobull@mail.com
Subject: Re: Package Positioning
Message-Id: <u9k871yswt.fsf@wcl-l.bham.ac.uk>
"Christopher Hahn" <chahn@peregrine.com> writes:
> use SCUnixLog;
>
> This worked nicely. (Note: I did use theproper extension)
>
> My question is: why does this fail when I put the module
> into the subdirectory:
> /usr/local/lib/perl5/site_perl/5.6.0/Peregrine
>
> and change the script's use line:
> use Peregrine::SCUnixLog;
You probably forgot to change the module's package name to match its
new file name.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 08 Feb 2001 15:33:00 GMT
From: edis9@my-deja.com
Subject: Re: perl -V error
Message-Id: <95ue7c$qqg$1@nnrp1.deja.com>
Reinstalling perl did the trick! Thanks to all who helped me!
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 08 Feb 2001 15:58:31 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: Perl DBI newbie question ...
Message-Id: <Gmzg6.175135$I9.10656846@news5.aus1.giganews.com>
"Joe Halbrook" <permission2@home.com> wrote in message
news:I4ng6.112589$g6.50011773@news1.elmhst1.il.home.com...
> I was curious about something:
>
> When I run my script using telnet it works fine.
I assume you me from the unix shell.
> When I call it from a browser, which loads a
> pop-up window, then does some DBI stuff,
> the pop-up works fine, but the DBI stuff blows.
I assume you mean as a CGI application.
> Do I have to do something special when calling
> the script from a browser?
>
> Code ...
>
> use DBI;
>
> $agent = "$ENV{'HTTP_USER_AGENT'}";
> $remote = "$ENV{'REMOTE_ADDR'}";
> $ref = "$ENV{'HTTP_REFERER'}";
>
> my $database_name = $db;
> my $location = "12.34.56.789";
> my $port_num = "3306";
> my $database =
> "DBI:mysql:$database_name:$location:$port_num";
> my $db_user = "user";
> my $db_password = "pswd";
>
> my $dbh = DBI->connect($database,$db_user,$db_password);
>
> my $sth = $dbh->prepare("INSERT INTO ct$table
> (ctDate,hostID,userAgent,ipAddr,refURL)
> VALUES
> (NULL,'$host','$agent','$remote','$ref')");
>
> $rows = $sth->execute();
>
> $sth->finish();
> $dbh->disconnect();
>
> exit(0);
This code does not check for errors. You should use the "-w" flag and
probably "use strict". You are not trapping errors in your DBI functions.
Look at PrintError and RaiseError for your connect function. You are also
not returning anything to the browser and if you were you are not creating
the proper header to do so. Look at using CGI.pm. Also look at CGI::Carp to
trap and format errors.
jay
------------------------------
Date: Thu, 08 Feb 2001 15:09:02 GMT
From: lkenny@fisheries.org (LK)
Subject: Re: Place an array item in a specific place.
Message-Id: <3a82b65d.3112410@wingate>
On Wed, 07 Feb 2001 21:01:24 GMT, lkenny@fisheries.org (LK) wrote:
>I have already tried perlfaq1-4 for this answer, but couldn't quite
>get it.
>I have an ordered array that I need to contain a specific number of
>items. Some of the items just serve as a place holder in the array so
>that a program can go through each array and pick out the proper info
>that is listed in the corresponding array index spot.
>I.E., I need $item[6] of the array @info to always be the city and
>state of the record. But since some people have Aprtment or suite
>numbers, sometimes it becomes $item[7].
>I want to now if i can insert a basicall blank line or blank element
>into the array where I need to to serve as a place holder. And if so,
>how?
>I am not posting my code because I don't think it will be that
>helpful.
>If you could help me out or point me to a source IU would appreciate
>it.
>
>Thanks,
>
>LK
Thanks Tad and Tony. I think it is going to be more complicated then
I want it tobe. But I was hoping to sneak away with one without a lot
of work. Oh, well.
Thanks for the help.
LK
------------------------------
Date: Fri, 9 Feb 2001 23:40:24 +0800
From: "Regent Linus" <wstsoi@hongkong.com>
Subject: Please help, my WIN32::API script cant run after upgrading ActivePerl5.22 to 6.23
Message-Id: <95uojo$fda1@imsp212.netvigator.com>
Hi
I was really very troubled by this problem for few weeks.
Thanks to anyone who look into my post.
Last time I made a Text to Speech agent DLL and called it
by my Perl script, it worked fine (thanks to help of Tye McQueen),
but few days ago I just updated my ActivePerl5.22 to 6.23 and
ran the script again, a debug window poped out and with the
following message:
*****************WINDOW ERROR*******************
ERL caused an invalid page fault in
module PERL56.DLL at 017f:2803aa2a.
Registers:
EAX=0176f344 CS=017f EIP=2803aa2a EFLGS=00010246
EBX=0176f6fc SS=0187 ESP=0153fbd4 EBP=0153fc14
ECX=017cc644 DS=0187 ESI=00000001 FS=a97f
EDX=819177ec ES=0187 EDI=01779f60 GS=0000
Bytes at CS:EIP:
8b 3e 8b 4e 0c 8b 55 d8 8b c7 2b c1 42 c1 f8 02
Stack dump:
00000001 0176f344 00000000 0176f344 017cbbd8 00000004 00000000 0177979c
0153fc14 2803b31d 0176f344 017cbbd8 00000000 0176d8c8 0176f344 017cc644
The TTS DLL has 3 main functions: initialization, speak and termination
and they are defined as:
***************DLL FUNCTIONS DEFINITION**************
int initTTS(char *dataPath, short gender);
int spkTTS(char *string, double sentenceRate, short gender);
void termTTS(void);
My perl script can't even just unitialize the TTS, I ever put a die() after
initCTTS,
it just died without any "init ok, ready to go", and just poped out the
debug window.
But my initCTTS only takes into 2 simple parameters, should I look into my
initCTTS.cpp?
It is weird, why it could be ok at 5.22, but not 6.23, actually I have tried
some other
version of 6.XX, but it failed just as the same as 6.23.
Could anyone help me?
Any Clues?
Thanks very very much.
*********************MY PERL SCRIPT*********************
*********WORK FINE AT ACTIVEPERL5.22, but not 6.23**********
use Win32::API;
$the_string = "blah blah blah I am speaking";
$initCTTS = new Win32::API("cutalk", "initCTTS", [P, I], I) || die("NEW Init
failed");
$spkCanton = new Win32::API("cutalk", "spkCanton", [P, N,N, I], I) ||
die("NEW Spk failed");
$termCTTS = new Win32::API("cutalk", "termCTTS", [], V) || die("NEW Term
failed");
if ($initCTTS->Call('e:\\ctts_dll\\datafile',1) == 1 ){
print "init ok, ready to go\n";
}
else {die("Init failed");}
my $val =2.0;
my $buf =pack("d", $val);
my $addr= 0 + \$buf;
if ( ($spkCanton->Call($the_string, @ints, 1)) == 1) {
print "SpkCanton returned 1";}
else {
print "SpkCanton returned 0";
}
$termCTTS->Call();
*************************************************
*****************My initctts.cpp********************
*************************************************
#include <stdio.h>
#include <string.h>
#include "extractsent.h"
#include "xscript2parameter.h"
#include "pause.h"
#include "uvdur.h"
#include "psola.h"
#define IN_DLL
#define DllExport extern "C" __declspec( dllexport )
#define MAX_LENGTH_PER_SENTENCE 2048
char fileDirCTTS[1024];
PAUSE_LIST pauses; file://for "cusent_copause.txt"
DURATION_LIST pause_durations; // for "cusent_uvdur.txt"
unsigned long DICT_SIZE; // size of dict.txt
char **dict_chn;
char **dict_pron;
extern void load_all_symbols();
extern int load_pron_dict_file(char *path);
int load_sylpause();
int load_duration();
// female
DATA_IDX *voice1_idx; // voice1 index
short *voice1_dat; // voice1 data
long *voice1_pm; // voice1 pitch mark
long VOICE1_IDX_SIZE;
// male
DATA_IDX *voice2_idx; // voice2 index
short *voice2_dat; // voice2 data
long *voice2_pm; // voice2 pitch mark
long VOICE2_IDX_SIZE;
int load_voice1(char *path);
int load_voice2(char *path);
DllExport int initCTTS(char *dataPath, short gender){
if (dataPath==NULL){
strcpy(fileDirCTTS, "");
}
else{
strcpy(fileDirCTTS, dataPath);
strcat(fileDirCTTS, "\\");
}
load_all_symbols();
if( load_pron_dict_file(fileDirCTTS)==0 ){
printf("error: load lexicon\n");
return 0;
}
if( load_sylpause()==0 ) {
printf("Error: Load Syllable Pause\n");
return 0;
}
if( load_duration()==0 ){
printf("Error: Load Duratio\n");
return 0;
}
switch(gender){
case 2: // M_VOICE
if( load_voice2(dataPath)==0 ){
printf("Error: Load Voice1\n");
return 0;
}
break;
case 3: // M_VOICE|F_VOICE
if( load_voice2(dataPath)==0 ){
printf("Error: Load Voice1\n");
return 0;
}
default: // F_VOICE
if( load_voice1(dataPath)==0 ){
printf("Error: Load Voice1\n");
return 0;
}
}
return 1;
}
DllExport void termCTTS(void){
if(voice1_idx)
free(voice1_idx);
if(voice1_dat)
free(voice1_dat);
if(voice1_pm)
free(voice1_pm);
if(voice2_idx)
free(voice2_idx);
if(voice2_dat)
free(voice2_dat);
if(voice2_pm)
free(voice2_pm);
}
int load_sylpause(void){
file://int i;
pauses.num_pause = PAUSE_CO;
pauses.pause = cu_pause;
return pauses.num_pause;
}
int load_duration(void){
file://int i;
pause_durations.num_duration = (long) DURATION_UV;
pause_durations.duration = UVDuration;
return 1;
}
file://female
int load_voice1(char *path){
FILE *fpdata, *fpidx;
char buf[1024];
long size_idx;
file://long i;
long ttl_size; file://total size of data file (*.dat)
// voice1.idx
strcpy(buf, path);
if( strlen(path)>0 ){
strcat(buf, "\\");
strcat(buf, "voice1.idx");
}
else{
strcpy(buf, "voice1.idx");
}
fpidx=fopen(buf, "rb");
if(fpidx==NULL){
printf("error: fpidx\n");
return 0;
}
fseek(fpidx, 0, SEEK_END);
size_idx=ftell(fpidx)/sizeof(DATA_IDX);
VOICE1_IDX_SIZE=size_idx;
voice1_idx=(DATA_IDX*)malloc(VOICE1_IDX_SIZE*sizeof(DATA_IDX));
if(voice1_idx==NULL){
printf("error: voice1_idx\n");
return 0;
}
rewind(fpidx);
fread(voice1_idx, sizeof(DATA_IDX), VOICE1_IDX_SIZE, fpidx);
fclose(fpidx);
// voice1.dat
strcpy(buf, path);
if( strlen(path)>0 ){
strcat(buf, "\\");
strcat(buf, "voice1.dat");
}
else{
strcpy(buf, "voice1.dat");
}
fpdata=fopen(buf, "rb");
if(fpdata==NULL){
printf("error: fpdata\n");
return 0;
}
fseek(fpdata, 0, SEEK_END);
ttl_size=ftell(fpdata);
rewind(fpdata);
voice1_dat=(short*)malloc(voice1_idx[0].ptPM);
if(voice1_dat==NULL){
printf("error: voice1_dat\n");
return 0;
}
fread(voice1_dat, sizeof(short), voice1_idx[0].ptPM/sizeof(short), fpdata);
voice1_pm=(long*)malloc(ttl_size-voice1_idx[0].ptPM);
if(voice1_pm==NULL){
printf("error: voice1_pm\n");
return 0;
}
fread(voice1_pm, sizeof(long), (ttl_size-voice1_idx[0].ptPM)/sizeof(long),
fpdata);
fclose(fpdata);
return 1;
}
file://male
int load_voice2(char *path){
FILE *fpdata, *fpidx;
char buf[1024];
long size_idx;
file://long i;
long ttl_size; file://total size of data file (*.dat)
// voice2.idx
strcpy(buf, path);
if( strlen(path)>0 ){
strcat(buf, "\\");
strcat(buf, "voice2.idx");
}
else{
strcpy(buf, "voice2.idx");
}
fpidx=fopen(buf, "rb");
if(fpidx==NULL){
printf("error: fpidx\n");
return 0;
}
fseek(fpidx, 0, SEEK_END);
size_idx=ftell(fpidx)/sizeof(DATA_IDX);
VOICE2_IDX_SIZE=size_idx;
voice2_idx=(DATA_IDX*)malloc(VOICE2_IDX_SIZE*sizeof(DATA_IDX));
if(voice2_idx==NULL){
printf("error: voice2_idx\n");
return 0;
}
rewind(fpidx);
fread(voice2_idx, sizeof(DATA_IDX), VOICE2_IDX_SIZE, fpidx);
fclose(fpidx);
// voice2.dat
strcpy(buf, path);
if( strlen(path)>0 ){
strcat(buf, "\\");
strcat(buf, "voice2.dat");
}
else{
strcpy(buf, "voice2.dat");
}
fpdata=fopen(buf, "rb");
if(fpdata==NULL){
printf("error: fpdata\n");
return 0;
}
fseek(fpdata, 0, SEEK_END);
ttl_size=ftell(fpdata);
rewind(fpdata);
voice2_dat=(short*)malloc(voice2_idx[0].ptPM);
if(voice2_dat==NULL){
printf("error: voice2_dat\n");
return 0;
}
fread(voice2_dat, sizeof(short), voice2_idx[0].ptPM/sizeof(short), fpdata);
voice2_pm=(long*)malloc(ttl_size-voice2_idx[0].ptPM);
if(voice2_pm==NULL){
printf("error: voice2_pm\n");
return 0;
}
fread(voice2_pm, sizeof(long), (ttl_size-voice2_idx[0].ptPM)/sizeof(long),
fpdata);
fclose(fpdata);
return 1;
}
------------------------------
Date: Thu, 08 Feb 2001 14:33:20 GMT
From: paulvanderheijden@my-deja.com
Subject: Problems with find.pl and winnt
Message-Id: <95uanh$nan$1@nnrp1.deja.com>
Question from a newbie.
I'm trying to create an index-file for a search
engine for our website.
In order to do this all pages should be indexed.
The problem I encounter is that my script,
although it should, does not index files in any
subdirectory.
Here's a code snippet:
@SEARCHDIRS=("\\nivel"");
$INDEXFILE='index.idx';
require "find.pl";
open(INDEX,">$INDEXFILE");
&find (@SEARCHDIRS);
The indexfile contains references to the files in
directory 'nivel', but not to files in any of
nivel's subdirectories.
What do I do wrong? I'm using Perl 5.001 which
comes from the windows NT4.0 resourcekit
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 08 Feb 2001 17:13:48 GMT
From: jrpink@my-deja.com
Subject: setting degree of parallelism
Message-Id: <95uk43$pn$1@nnrp1.deja.com>
I have a number of tasks which run faster with multiple processes, so I am
setting up a perl script which I can wrap around those jobs. In this
example, I am just creating 10 files, printing something in them and exiting.
The idea is to have a number of child processes equal to the $dop (degree of
parallelism) variable do the work. Everything works fine in the script
below, which I cobbled together from a number of examples on forking. The
problem is when I set the $dop to 1, the first task completes, the child is
reaped, then the process just sits there spinning on the signal handler, I
think.
The whole point of this script is to have $dop set greater than one, but
since I don't understand what is happening when it is one, my ingnorance is
probably more advanced than I thought.
If anyone can provide some insight as to what is happening, I'd greatly
appreciate it.
John
#!/usr/local/bin/perl -w
use POSIX ":sys_wait_h";
## doesn't work when dop is 1
## parent just sucks up cpu.
@files = qw(test1 test2 test3 test4 test5 test6 test7 test8 test9 test10);
$children = 0;
$SIG{CHLD} = \&REAPER;
$dop = 1; # degree of parallelism
while(@files)
{
$file = shift(@files);
if ($children < $dop)
{
$children++;
if ($pid = fork) # parent
{
print("pid: $pid\n");
}
else # child
{
open(FH,">$file");
for ($i = 0;$i<10000 * @files;$i++)
{ print FH "This is test line $i written by child: $children\n"; }
close(FH);
exit 0;
}
}
else
{
print("too many children, sleeping\n");
unshift (@files,$file);
sleep 1;
}
}
sub REAPER { my $child; while ($child = waitpid(-1,WNOHANG)) {
print("error code: $?\n"); #$Kid_Status{$child} = $?; # commentd out, I
don't know what this line is for. JP if ($child != -1) { print("reaped:
$child\n"); $children--; print("children: $children\n"); } } }
exit 0;
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 245
**************************************