Flemming Greve Skovengaard wrote: > > John W. Krahn wrote: >> >> Flemming Greve Skovengaard wrote: >>> >>> $rand_string .= $letters[$index]; >> >> Or simply: >> >> $rand_string .= $letters[ rand @letters ]; > > Yes, that would save a line of code, a variable and a call to scalar(). > But shouldn't that be: > > $rand_string .= $letters[ int rand @letters ]; > > instead?
The array index can only be an integer, in other words $letters[ 4.41792527 ] makes no sense so perl converts the value of the index to an integer so the use of int() is redundant. $ perl -le' my @x = 0 .. 29; for ( map rand( @x ), 1 .. 20 ) { print "Index: $_ Element: $x[$_]" } ' Index: 16.1372656909499 Element: 16 Index: 10.402236874601 Element: 10 Index: 4.93827622731633 Element: 4 Index: 27.3864972245868 Element: 27 Index: 21.1438057726559 Element: 21 Index: 7.22816484936587 Element: 7 Index: 22.9971373378341 Element: 22 Index: 29.53992680071 Element: 29 Index: 15.1167304904378 Element: 15 Index: 25.5722310830811 Element: 25 Index: 13.2102360627812 Element: 13 Index: 13.9166707961743 Element: 13 Index: 10.0541861527287 Element: 10 Index: 4.68597889657119 Element: 4 Index: 14.1321285416915 Element: 14 Index: 11.4443306977078 Element: 11 Index: 27.0749844462484 Element: 27 Index: 6.42358929265441 Element: 6 Index: 6.55100443825493 Element: 6 Index: 0.438573083256628 Element: 0 John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/