Gossamer Forum
Home : General : Perl Programming :

remove element in array

Quote Reply
remove element in array
i have a field $players that contains the following:
i'm opening a file and as i go thru the records i'm comparing one field ($playerID) to the list of $players. if $playerID is in the list of $players, i want to remove that playerID from $players. what is the best way to do this? it's not an actual change to $players, so i could use a temporary field or array to hold the remaining players.
Quote Reply
Re: [delicia] remove element in array In reply to
Something like this?

my $player_to_remove = "bevs";
my $test = q|delicia~~bevs~~golfer31~~nancy|;
my @new;
foreach (split /~~/, $test) {
next if $_ =~ /$player_to_remove/i;
push @new, $_;
my $new_users = join "~~", @new;

Basically just loop through the users you have, and skip if it matches the one you want to remove. Then re-join the strings and you have the new string without the one you removed :)


Andy (mod)
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] remove element in array In reply to
thanks! all is working now.