Solved

print spaces without typing them all

Posted on 2007-11-21
2
1,535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 total points
ID: 20331582
for my $i (1..3) {
  print ' ' x $i ."a\n";
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Six Sigma Control Plans

636 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