Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

by AnomalousMonk (Bishop)
on Jul 26, 2020 at 17:58 UTC ( #11119833=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

I found an example that works on an array with the form @array = ( "aaaa" , "bbbb" , "cccc" , "dddd" ), but it refuses to work for my @history array ( the parens in the string(s) ? )

Impossible to say. You've provided no code to examine.

Here's something that may work IIUC your requirements:

c:\@Work\Perl\monks>perl -wMstrict -le "use List::MoreUtils qw(part); ;; my @history = qw(Cache::SizeAwareMemoryCache(3) dhcp-options(5) BN_ad +d_word(3) audit-packages(8)); my $choice = 'dhcp-options(5)'; print qq{before: (@history)}; ;; @history = map @$_, part { $_ ne $choice ? 0 : 1 } @history; print qq{after: (@history)}; " before: (Cache::SizeAwareMemoryCache(3) dhcp-options(5) BN_add_word(3) + audit-packages(8)) after: (Cache::SizeAwareMemoryCache(3) BN_add_word(3) audit-packages( +8) dhcp-options(5))
Note that this will remove and append all matching strings to the end of the array, not just the first one. See List::MoreUtils::part().

WRT this comment by LanX which I just saw, note that the solution above uses exact string comparison, not regex comparison. If you're using regexes, the approach must be slightly different.

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2021-03-02 20:37 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (62 votes). Check out past polls.