Is it possible to assign the output of the printf function to a scalar
variable instead of writing the output to STDOUT?

For instance, I would like the output of printf stored in $text:

  $format = '| %4s | %-16s | %6s | %6s | %4s |';
  @data   = 'col1' .. 'col5';

  $text   = printf $format, @data;

However, what actually happens is the value 1 is stored in $text and the
formatted data are written to STDOUT. I assume the value of 1 is a
successful exit code.

I was able to accomplish this task via two steps:

  $list = join ',' => @data;
  $text = `perl -e "printf '$format', $list"`;

$text now contains
'| col1 | col2              |    col3 |   col4 | col5 |'

Does anyone know of a "simpler" way?

TIMTOWTDI
Thanks.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to