Okay, a newbie here. I'm trying to do a very simple little "secret code" script that prompts the user for a message, then substitutes the letters based on a randomly generated alphabet, made fresh each time. The problem comes when I try to drop the $string into the tr// operation. From searching around forums and looking at the manual, I think it has something to do with eval() being needed to interpolate the $string. Greatly appreciate any perls of wisdom! Many thx. Jamie
#!/usr/bin/perl # transliterate.pl use strict; use warnings; print "Please enter your message to be encrypted.\n"; my $message = <STDIN>; chomp($message); # generate randomized alphabet my @chars = ("A".."Z", "a".."z"); my $string; $string .= $chars[rand @chars] for 1..26; # I want to drop the random alphabet in $string into the replace-with +slot of tr// my $code = eval($message =~ tr/abcdefghijklmnopqrstuvwxyz/$string/); print "Here is your encrypted message: $code\n"; # As is, $code returns the number of letters in the message.
In reply to secret code, transliteration prob by henzcoop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |