Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by choroba (Archbishop)
on Jul 27, 2020 at 14:28 UTC ( #11119863=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

You can also use the stable sort, sorting by whether the string equals the choice. The ones that don't will be sorted as zeroes, i.e. at the beginning of the list, the one that does will be sorted as 1, i.e. will go to the end of the list.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use sort 'stable'; use List::UtilsBy qw{ sort_by }; my @history = ( 'Cache::SizeAwareMemoryCache(3)' , 'dhcp-options(5)' , + 'BN_add_word(3)' , 'audit-packages(8)' ); my $choice = 'dhcp-options(5)'; @history = sort_by { $_ eq $choice } @history; say "@history";

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2020-11-24 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?