Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:

In the hope that this doesn't force a reevaluation of the old maxim "there's no such thing as a stupid question.", I'd like to find out what command to use to create a variable length scalar like this (eg, supposing there was a command CharString), it would return

CharString('*', 3) = '***' CharString(' ', 5) = ' ' # ie 5 spaces CharString('y', 0) = ''

Replies are listed 'Best First'.
Re: Building strings of specific length
by Corion (Patriarch) on Oct 14, 2009 at 17:27 UTC
Re: Building strings of specific length
by ikegami (Patriarch) on Oct 14, 2009 at 17:36 UTC

    Trying to guess at the bigger picture, you might also be interested in sprintf

    printf("[%5d]\n", 123); # Prints [ 123]

    and Perl6::Form (it brings Perl 6's forms to Perl 5).

    use Perl6::Form; print form " =================================== ", "| NAME | AGE | ID NUMBER |", "|----------+------------+-----------|", "| {<<<<<<} | {||||||||} | {>>>>>>>} |", $name, $age, $ID, "|===================================|", "| COMMENTS |", "|-----------------------------------|", "| {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[} |", $comments, " =================================== ";
Re: Building strings of specific length
by zwon (Abbot) on Oct 14, 2009 at 17:27 UTC
    print '*' x 3, "\n", ' ' x 5, "=\n", 'y' x 0, "=\n";
      Perfect. ++.