in reply to Random Text: There's got to be an easier way

Well, your @seed array is only 34 elements long -- which is not a big deal. Basically, you're looking for something that maps the range of numbers returned from the rand function to your desired set. If you had a less complicated filter (say, "any printable character"), then you could use an algorithmic approach, but for this small size, a lookup array is probably the best fit.

As for using strict, you just have to quote the letters in the range. Here's your same code a little shorter:

my @seed = ('a'..'z', 2..9); my $rand = ''; $rand .= $seed[rand(@seed)] foreach 1..7;
HTH

Replies are listed 'Best First'.
Re: Re: Random Text: There's got to be an easier way
by Hero Zzyzzx (Curate) on Jun 03, 2001 at 21:47 UTC

    Again, the beautiful thing about perl is that there can be many different ways to do the same thing simply and elegantly. Thanks to all for the quick help!!

    This is pretty much the code what I was looking at, though I need to learn to use "join" as beatnik pointed out above.

    The final version for me, unless someone gives me a compelling reason to use "join".

    my @seed=('a'..'z',2..9); my $rand=''; foreach(0..7){ $rand.=$seed[rand(@seed)]; }
      Benchmark, nuff said

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.