Hi Monks,
I have a Perl script that uses the time() fuction to create a (hopefully) unique ID (not the greatest method I realise). However when in a loop and creating ID automatically my program can sometimes run a little too fast and the ID's created are the same. I therefore want to add a little delay of say 5 seconds, inbetween each run of the loop. Is this really bad Perl practise? How can I do this? I thought about this method, but just wanted to check with you guys.
foreach (@loop) {
my $id=time();
print $id;
sleep 5;
}
Any idea's if this will work? This is of course a simplified version of my program just as an example.
Cheers, Tom
janitored by ybiC: Retitle from "sleeping a script", to improve future searchability
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|