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

Substitution of a particular letter in all combinations of positions in word (see inside)

by Doctrin (Beadle)
on Jan 09, 2013 at 12:55 UTC ( #1012471=perlquestion: print w/ replies, xml ) Need Help??
Doctrin has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone! Could you please tell me how to do the following. Say, we have a word ferber. I wanna substitute "e" with "a" in all combinations, so that I have following words:

farber

ferbar

farbar

Maybe, there is even a "one-line" solution? Thanks in advance

Comment on Substitution of a particular letter in all combinations of positions in word (see inside)
Re: Substitution of a particular letter in all combinations of positions in word (see inside)
by Anonymous Monk on Jan 09, 2013 at 13:08 UTC
    You first :)
Re: Substitution of a particular letter in all combinations of positions in word (see inside)
by LanX (Canon) on Jan 09, 2013 at 13:08 UTC
    DB<182> $s=join '{e,a}',split /e/,"ferber" => "f{e,a}rb{e,a}r" DB<183> @a=< $s > => ("ferber", "ferbar", "farber", "farbar")

    UPDATE

    one-liner

    DB<192> @a=glob(join '{e,a}',split /e/,"ferber") => ("ferber", "ferbar", "farber", "farbar")

    Cheers Rolf

      Amazing! Thank you very much

      ... and using the  /r substitution modifier of 5.14+:

      >perl -wMstrict -le "printf qq{'$_' } for glob('ferber' =~ s{e}{{e,a}}xmsgr); " 'ferber' 'ferbar' 'farber' 'farbar'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (20)
As of 2014-07-24 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (162 votes), past polls