http://qs321.pair.com?node_id=372245

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;