in reply to Re: Words without a Dictionary
in thread Words without a Dictionary

Thanks dragonchild, but excuse me for being thick, but what is the generated word output to? i tried printing $word, but that always comes out blank??

Replies are listed 'Best First'.
Re3: Words without a Dictionary
by dragonchild (Archbishop) on Jul 22, 2003 at 19:37 UTC
    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.