homepage Welcome to WebmasterWorld Guest from 54.167.11.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
consolidate duplications in an array? (perl)
littleman




msg:429845
 3:05 am on Feb 28, 2001 (gmt 0)

How would you all consolidate duplications in an array?
from:
@array = qw( 1 2 3 3 4 5 6 7 7 8 )
to:
@array = qw( 1 2 3 4 5 6 7 8 )

 

sugarkane




msg:429846
 11:18 am on Feb 28, 2001 (gmt 0)

The standard way is this:

foreach $i (@array) {
push @new_array, $i unless $tmp{$i}++;
}

For fun, I also tried this:

foreach $i (@array) {
$tmp.="$i " unless $tmp=~/$i/;
}
@new_array=split(" ",$tmp);

...but it's waaay slower.

littleman




msg:429847
 11:21 pm on Feb 28, 2001 (gmt 0)

Thank you Sugarekane. I actually was doing something along the lines of your second approach. I like the first approach much better.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved