in reply to Generating a random string of chars, easily.

The range operator will come in handy for this
die("Usage: $0 LENGTH") unless @ARGV; my @alpha = ( a .. z, A .. Z ); my $randstr = join '', map $alpha[rand @alpha], 0 .. shift; print "random string: $randstr", $/;

HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Generating a random string of chars, easily.
by Sihal (Pilgrim) on Nov 14, 2002 at 15:30 UTC
    Oh my god, it's so clear once you saw it !
    I keep forgeting about those shortcuts like the range operator, I was starting to write:
    my @alpa =('a','b',...) ;
    BTW isn't a int missing before the rand @alpha ?
    I mean, it works without it but it seems strange no?
      BTW isn't a int missing before the rand @alpha ?
      I mean, it works without it but it seems strange no?
      Since arrays indices are integer based, so perl automagically converts the given float to an int. I should imagine it would be rather awkward accessing the 2.53815239812875th element of an array ;)
      HTH

      _________
      broquaint

        I really like the word automagically, it really fits with perl. :)