Solved

print spaces without typing them all

Posted on 2007-11-21
2
1,522 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
remove string in script sql 10 97
What's wrong with this web.config regex? 3 50
Regular Expression Calculator Tester 2 87
regex code to remove .cn and .com 2 6
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
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…

763 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