Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How can i print N repeated characters?

by Doraemon (Beadle)
on Jul 07, 2004 at 01:48 UTC ( [id://372245]=perlquestion: print w/replies, xml ) Need Help??

Doraemon has asked for the wisdom of the Perl Monks concerning the following question: (strings)

How can i print N repeated characters? (in one single line's code or as simple as possible)
e.g
print repeat(5,'-'); # print out '-----'
thanx

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How can i print N repeated characters?
by gaal (Parson) on Jul 07, 2004 at 04:46 UTC
    print '-' x 5;
Re: How can i print N repeated characters?
by lithron (Chaplain) on Mar 10, 2006 at 15:37 UTC
    for (1..5) { print "-"; }
    Which prints the ----- you are looking for.

    If you want to print the number of the iteration you could use:
    for my $x (0..9) { print $x; }
    Which outputs 0123456789

      Or you could always do it this way:

      my $n = 5; print "-" x $n;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://372245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found