in reply to Filling An Array

You can definitely get rid of $count by using push. Here's how I'd do it:
for my $letter ('A'..'H') { for my $num (1..12) { push(@masterarray, sprintf("$letter%02d", $num)); } } print scalar(@masterarray)," elements\n";
If you wanted to use some magic, you could do this instead:
for my $letter ('A'..'H') { push(@masterarray, $letter.'01'..$letter.'12'); }
or even
# The golfiest my @masterarray = map { $_.'01'..$_.'12' } 'A'..'H';

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: Filling An Array
by Qiang (Friar) on Apr 23, 2004 at 03:39 UTC
    ++Roy

    I think even the golfiest way is very clear to a reasonable perl user. On the other hand, sprintf never catch my eyes.