Perl

Moderators: Jonathan
Number of threads: 1211
Number of posts: 3568

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Irregular performance Posted by dkenney1 on 26 Jan 2010 at 5:13 PM
Code is stupid...but people get mad if you dont try before asking for help. I get 18 rands to scratch.dat most of the time. However, some of the time, the hourglass comes up and I get only 12 results. Your ideas?
I appreciate it.
----
$seen = 0;
$reps = 1;
while ($reps < 19)
{
$random_number = int(rand(336)) +1;
if (-e "scratch.dat")
{
open (SCR, "scratch.dat") || &CgiDie ("SCRATCH could not be opened while attempting read");
@scra =<SCR>;
close (SCR);
foreach $mine (@scra)
{
chomp($mine);
($junk, $num_to_check) = split (/\|/, $mine);
if ($num_to_check == $random_number)
{
$seen = 1;
}
}#end of foreach line
}#end of if scratch data exists
if ($seen == 0)
{
open (SCR, ">>scratch.dat") || &CgiDie ("SCRATCH could not be opened while attempting write");
seek(SCR, 0, SEEK_END);
print SCR "junk\|$random_number\n";
close(SCR);
$seen = 0;
$reps++;
}
}# End of lets do 18 reps...
#unlink ("scratch.dat");
&printout;
}
else
{
&signin;
}
Report
Re: Irregular performance Posted by dkenney1 on 28 Jan 2010 at 10:47 AM
I got it. $seen = 0; belongs after while. Otherwise seen remains one after the first duplicate is encountered and it goes on and on....



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.