On 09/29/2006 12:15 PM, Derek B. Smith wrote:
--- "D. Bolliger" <[EMAIL PROTECTED]> wrote:

Derek B. Smith am Donnerstag, 28. September 2006
22:28:
Why not just specify a non-digit for the first
character:

my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');

my $password = join '', $a[ 10 + rand( @a - 10 )
],
map $a[ rand @a ], 1 .. 5;



John
Ok great, but I do not fully understand this. Will
you
explain in English?
Join with '':
a) a randomly selected entry from @a excluding the
digits
at positions 0..9 [the part between the 1st and 2nd comma]
b) five randomly selected entries from @a
   [the map part]

Note: @a is used in scalar context both times,
meaning the number of entries in @a.

perldoc -f map
perldoc -f join
perldoc -f rand


My tip for cases where you get a working solution
you don't understand fully:
a) Try to find out what "belongs together" (imagine
'()'s)
b) Try to break the solution apart according to the
findings in a)
c) examine the parts: print them out, dump them with
Data::Dumper, modify
   them, read the man pages
d) put them together again, eventually one by one
part, using examination techniques as in c)


Hope this helps!

Dani

I reread the docs and I am still unclear with the
code:
$a[ 10 + rand( @a - 10 )
I do understand everything but $a[ 10 + rand( @a - 10
)

b/c you say subtract 10 from each element occurrance
=> @a - 10 then add 10 to the result of rand (@a - 10)
To me this is offsets itself which is why I am
confused. Will you explain again?
I think you missed an explanation step between a and
b?

Reagardless it work so thank you.



Does this slice help demonstrate it?

my @a = (0..9,'a'..'z','A'..'Z');
my @b = @[EMAIL PROTECTED];
print @a, "\n";
print @b, "\n";

# OUTPUT:
#0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ
#

BTW, placing print statements in the right places is a great way to learn how someone's program works. Anyway, I hope this is easier to digest:

my @a = (0..9,'a'..'z','A'..'Z');
my @b = @[EMAIL PROTECTED];

my $password = $b[int rand (@b)];
$password .= join '', map $a[int rand (@a)], (1..5);
print $password, "\n";

__HTH__


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to