grep can do what you're trying to accomplish. Consider the following:
#! /usr/bin/perl use strict ; use warnings ; $|++ ; my @array = qw( foo bar match zoot zoot match match match ) ; my $item = 'match' ; print "Original size: " . @array . "\n" ; print "Original contents: " . join( " : ", @array ) . "\n\n" ; my @new_array = grep { ! /^$item$/ } @array ; print "New size: " . @new_array . "\n" ; print "New contents: " . join( " : ", @new_array ) . "\n\n" ; __END__
Results:
Update: Whoops, was doing the exact opposite of the poster's question. All better now.Original size: 8 Original contents: foo : bar : match : zoot : zoot : match : match : m +atch New size: 4 New contents: foo : bar : zoot : zoot
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
--Friedrich Nietzsche
In reply to Re: Deleting elements from array questions
by DamnDirtyApe
in thread Deleting elements from array questions
by chuleto1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |