in reply to I need a regExp to add spaces

Sounds like a job for sprintf.
$Coverage_limits = sprintf("%-11.11s", $Coverage_limits);
c.

Replies are listed 'Best First'.
Re^2: I need a regExp to add spaces
by Anonymous Monk on Mar 21, 2005 at 17:11 UTC
    c,
    $LimitValue = sprintf("%-1.1s", $LimitValue);
    Is it possible in the above line of code to make the 1's into variables? eg.
    $LimitValue = sprintf("%-$length.$lengths", $LimitValue);
    Thanks in advance
      Of course. The obvious way:
      my $vlen = 1; $LimitValue = sprintf("%-${vlen}.${vlen}s", $LimitValue);

      The "real" sprintf to do variable field sizes is:

      $LimitValue = sprintf("%-*s", $vlen, $LimitValue);

      You can also do:

      $formatter = sprintf( "%%-%d.%ds", $vlen, $vlen ); $LimitValue = sprintf($formatter, $LimitValue);
      if you wanted to reuse the formatter elsewhere.

      c.