Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

print spaces without typing them all

Posted on 2007-11-21
2
Medium Priority
?
1,546 Views
Last Modified: 2012-05-11
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"
0
Comment
Question by:dwcronin
  • 2
2 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 20331571
for my $i (1..3) {
  printf "%${i}s\n", 'a';
}
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 20331582
for my $i (1..3) {
  print ' ' x $i ."a\n";
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question