I'm trying to get random lower case/upper case in my 42 chars password. Somehow I instead get:
ucclcjuczlclucmlc0lcdlc5lc0ucdlccucmucquc5ucslc4lckucxuctlcvlcquclucpuc0ucvlczucducauczlcauc7lciucmlcplcjucolchucmucpuc9lcilcqlck
Here is my code:
@a = (0 .. 9, 'a' .. 'z');
@case = ('lc','uc');
my $x = join '', map { scalar $case[rand(0-2)], $a[int rand @a]} 0 .. 42;
print "$x\n";
Any Hints?
There are already several good answers, I will present two more, one that looks like how you were thinking, and the second using CPAN
First, in the manner of the OP: make anonymous subroutines which return the
uc
orlc
of their argument, then randomly invoke one or the other on a random character.Ok, so now you have learned about function invoking. For your password generation, we take a quick look to CPAN and find
String::Random
. It lets you generate random strings based on patterns.The last time I ran this I got