Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Removing chars from a word from an array

by ikegami (Patriarch)
on Jan 24, 2006 at 16:05 UTC ( [id://525215]=note: print w/replies, xml ) Need Help??


in reply to Removing chars from a word from an array

Let's try this again!

my $word = 'abracadabra'; my @list = qw( a b c d e ); my %list = map { $_ => 1 } @list; foreach (@list) { delete $list{$_} if $word =~ s/\Q$_//; } @list = keys %list; print("remaining word: ", $word, "\n"); # raaabra print("remaining list: ", @list, "\n"); # e
outputs
remaining word: raaabra remaining list: e

If you wish to replace all intances of the characters in @list, replace s/\Q$_// with s/\Q$_//g. The output would then be the following for the above snippet:

remaining word: rr remaining list: e

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found