Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Removing chars from a word from an array

by GrandFather (Saint)
on Jan 24, 2006 at 21:35 UTC ( [id://525321]=note: print w/replies, xml ) Need Help??


in reply to Removing chars from a word from an array

Parts of the following may get you where you want to go:

use strict; use warnings; my $word = 'committee'; my @list = qw(t r e e); my %remove; $remove{$_}++ for @list; for my $letter (keys %remove) { --$remove{$letter} while $remove{$letter} and $word =~ s/$letter// +; } #rebuild list @list = (); for my $letter (keys %remove) { push @list, $letter while $remove{$letter}--; } print "Edited word: $word\nEdited list: @list";

Prints:

Edited word: commit Edited list: r

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found