CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Taking items out of an array

 



AsmirA
Deleted

Aug 31, 2000, 10:24 AM

Post #1 of 2 (345 views)
Taking items out of an array Can't Post

Is there a way to take out a specific assignment from an array, and making the array shorter...

I have this code..

@matches1=qw(Knights Nemesis Comets PiranasA Extreme PiranasB Strikers Panthers Cyclone Tigers);

@matches2=qw(Knights Nemesis Comets PiranasA Extreme PiranasB Strikers Panthers Cyclone Tigers);

$ran1 = rand(10);
$ran2 = rand(10);
$int1 = int($ran1);
$int2 = int($ran2);
if ($int1 != $int2)
{
print "$matches1[$int1] vs $matches2[$int2]\n";
}

but the hard part is when I need to take out the assignment that I have specified, the array is not shorten.

My intention is to fix the matches randomly and matches do not appear again.


japhy
Enthusiast

Aug 31, 2000, 10:36 AM

Post #2 of 2 (345 views)
Re: Taking items out of an array [In reply to] Can't Post

You want the splice() function:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


@names = qw( Joe Jack Bob Bill Jason );
splice @names, 2, 2; # remove $names[2] and $names[3]
</pre><HR></BLOCKQUOTE>

For more examples, read the splice() documentation. perldoc -f splice

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives