in reply to Play and win the word morph game with the help of Perl :)

die <<HELP unless @ARGV == 2; usage: transform.pl <word1> <word2> The program finds a way from one word to other, like this: % transform.pl love shit love-lose-lost-loot-soot-shot-shit HELP my $left = shift(@ARGV) || 'love'; my $right = shift(@ARGV) || 'shit';
Because you die if there are not two arguments on the command line there is no way that $left and $right will ever be assigned the values 'love' and 'shit'.
for ($left, $right) { $_ = lc; tr/A-Za-z//cd; }
You want to keep A-Z characters in a lc()ed string? What about non-ASCII lower case letters?

Replies are listed 'Best First'.
Re^2: Play and win the word morph game with the help of Perl :)
by Ieronim (Friar) on Jun 28, 2006 at 21:28 UTC
    Thanks.
    I modified the code according to your recommendations — i removed useless default values for $left and $right (theoreticaly the user can enter transform.pl 'test' '', but in this case he will get a VERY unexpected result :)) and removed the tr/// string.
      I never said that you should remove the tr/// operator, I was just wondering if you understood exactly what it was doing, or not doing? For instance, after $_ = lc; there should be no upper case letters in $_ so including A-Z in the list makes little sense.
        i understand what it does :)
        using tr/a-z//cd i removed all letters not in basic English alphabet, so the script could not be used for most other languages. i removed this line as it was a silly limitation.