Solved

print spaces without typing them all

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

Technology Partners: 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
XML::LibXML and Xpath syntax How do I get attribute of sibling 2 181
Perl Frameworks 1 119
Regex HELP 2 55
REGEXEXTRACT in google sheets 2 33
I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
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…
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…

739 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