Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
I was musing over The Name Game, which is a string-processing algorithm as well as a song.
According to the instructions, I have written this script:
$N = $ARGV[0]; $n = $N =~ /^[AEIOU]/ ? $N : substr( $N, 1 ); @a = qw( b f m ) if $N !~ /^[BFM]/; $n = lc( $n =~ /^[BFM]/ ? substr( $n, 1 ) : $n ); printf( "%s, %s, bo-%s%s, Banana-fana fo-%s%s, Fee-fi-mo-%s%s, %s!", ( $N, $N, $a[0], $n, $a[1], $n, $a[2], $n, $N ) );
I'm sure other Monks can improve on that?
Edit: based on the input below, this is a revised version:
$N = $ARGV[0]; $n = $N =~ /^[AEIOU]/ ? $N : substr( $N, 1 ); foreach (qw( b f m )) { push( @a, ( $N =~ /^[$_]/i ? '' : $_ ) ) } $n = lc( $n =~ /^[BFM]/ ? substr( $n, 1 ) : $n ); printf( "%s, %s, bo-%s%s, Banana-fana fo-%s%s, Fee-fi-mo-%s%s, %s!\n", ( $N, $N, $a[0], $n, $a[1], $n, $a[2], $n, $N ) );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The Name Game and Golf
by ambrus (Abbot) on Apr 19, 2010 at 09:02 UTC | |
by Cody Fendant (Hermit) on Apr 19, 2010 at 11:22 UTC | |
by Cody Fendant (Hermit) on Apr 19, 2010 at 11:33 UTC | |
|
Re: The Name Game and Golf
by youlose (Scribe) on Apr 19, 2010 at 10:55 UTC | |
|
Re: The Name Game and Golf
by youlose (Scribe) on Apr 19, 2010 at 13:25 UTC | |
by ambrus (Abbot) on May 03, 2010 at 16:27 UTC | |
|
Re: The Name Game and Golf
by youlose (Scribe) on Apr 19, 2010 at 11:01 UTC |