in reply to To register or not (part 2)

I guess you missed it in the chatterbox when I said you had an extra semicolon in your for construct. Instead, you put in an extra extra semicolon.

Taking them both out:
sub password { my( $s ) = @_; srand( $s ^ time ); my @c = split / */, "bcdfghjklmnpqrstvwxyz"; my @v = split / */, "aeiou"; for ( my $i = 1; $i <= 4; $i++ ) { return( $c[ rand @c ], $v[ rand @v ] ); } }
But the error there is pretty obvious: you return from password on the very first iteration through the for loop.

I'm guessing that what you really want to do is accumulate all those things in an array, and return them at the end:
sub password { my( $s ) = @_; srand( $s ^ time ); my @c = split / */, "bcdfghjklmnpqrstvwxyz"; my @v = split / */, "aeiou"; my @result; for ( my $i = 1; $i <= 4; $i++ ) { push @result, $c[ rand @c ], $v[ rand @v ]; } return @result; }
This can be made even more idiomatic by using map:
sub password { my( $s ) = @_; srand( $s ^ time ); my @c = split / */, "bcdfghjklmnpqrstvwxyz"; my @v = split / */, "aeiou"; return map { $c[ rand @c ], $v[ rand @v ] } 1..4; }
Other things I did to make it "better":
  1. Declare all local variables with my.
  2. Assign $s the first element of @_, rather than the length of @_.
  3. Pass the length of each array to the corresponding call to rand. That way you don't have to hard-code the lengths. (No "magic numbers".)
  4. Remove the int inside the array index; numbers are automatically int-ified in that context.
  5. Increment $i using ++ rather than +=1.

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.