Thanks ya'll,
I forgot to mention that my hosts needed to be in a list...also the reason I wanted to not require an external call is because the script calling my hosts doesn't belong to me thus I was attempting to make the code simple and not require additional Modules to be installed/called...
After some thought/research I have decided upon the following code as my solution...
#!/usr/bin/perl
sub get_hosts {
@hosts=("host1.domain.com","host1.domain.com","host1.domain.com","h
+ost1.domain.com");
@app = ();
while (@hosts) {
$rv = int(rand(@hosts));
push @app,$hosts[$rv];
$hosts[$rv] = $hosts[$#hosts];
pop @hosts;
}
$thosts = "$app[0],$app[1],$app[2],$app[3]";
return $thosts;
}
print &get_hosts();
Thanks again everyone for your suggestions...
Danny
-
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.
|