in reply to Padding with \s

try:

my $var = 'LR20SR37PD30LR23CR23BT01H'; $var .= ' ' x 40 - length($var);
or
my $var = 'LR20SR37PD30LR23CR23BT01H'; $var = substr($var . ' ' x 40, 0, 40);
or
my $var = 'LR20SR37PD30LR23CR23BT01H'; $var = sprintf '%-40s', $var;

Replies are listed 'Best First'.
Re: Re: Padding with \s
by bronto (Priest) on Sep 13, 2002 at 14:10 UTC

    You forgot pack:

    $string = 'abcd' ; $padded = pack('A40',$string) ; print "[$padded]\n" ;

    prints [abcd                                  ]

    ;-)

    Ciao!
    --bronto

    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->made($love) ;
    }