print spaces without typing them all

Using Perl and hopefully regular expressions, how do I print a specific number of characters like spaces?

For example. I want to make a "for" loop that counts to three and then have the program print out:
1 space then "a"
2 spaces then "a"
3 spaces then "a"
dwcroninAsked:
Who is Participating?
 
TintinCommented:
for my $i (1..3) {
  print ' ' x $i ."a\n";
}
0
 
TintinCommented:
for my $i (1..3) {
  printf "%${i}s\n", 'a';
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.