http://qs321.pair.com?node_id=11119838


in reply to Re^2: Removing a string-element from an array of strings
in thread Removing a string-element from an array of strings

As LanX said, you need to use quotemeta(or \Q) for the parentheses.

Here might be what you want.

#!/usr/bin/perl use strict; use warnings; my @history = ( "Cache::SizeAwareMemoryCache(3)" , "dhcp-options(5)" , + "BN_add_word(3)" , "audit-packages(8)" ); my $choice = "dhcp-options(5)"; @history = grep !/\Q$choice\E/, @history; # '\Q' to quotemeta push @history, $choice; print "@history";
Prints:

C:\Old_Data\perlp>perl test3.pl Cache::SizeAwareMemoryCache(3) BN_add_word(3) audit-packages(8) dhcp-o +ptions(5) C:\Old_Data\perlp>