You are being thick. $word is a variable that's scoped to the generate_password() subroutine. Of course, you can't print it out. Try printing the value returned by calling the subroutine, as seen below:
#!/usr/bin/perl
{
my @words = qw( perl monk vroom );
my %convert = (
i => '!', e => '#', s => '%', o => ')',
);
sub generate_password
{
my $word = $words[rand @words] . $words[rand @words];
$word =~ s/(.)/$convert{$1} || $1/eg;
$word;
}
}
print generate_password(), $/;
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. |