Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Removing a string-element from an array of strings

by Cristoforo (Curate)
on Jul 26, 2020 at 18:55 UTC ( #11119838=note: print w/replies, xml ) Need Help??


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>

Replies are listed 'Best First'.
Re^4: Removing a string-element from an array of strings
by AnomalousMonk (Bishop) on Jul 26, 2020 at 21:35 UTC
    push @history, $choice;

    What if the $choice was not found in the @history array?


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119838]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-12-02 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (35 votes). Check out past polls.

    Notices?