Perl adds printf output (s) to the string

I am parsing some data and organizing it, and now I need to commit it inside a variable.

I have never used printf or sprintf before.

I use printf in this way to organize the data:

printf("%-30s %18s %18s\n", "$a", "$b", "$c\n");

Now I have a variable that stores the string, and I want to add organized data to the $ result variable.

I tried something like

$result.printf("%-30s %18s %18s\n", "$a", "$b", "$c\n");

and it does not work. I also tried sprintf.

Any ideas?

Thanks, S

+5
source share
2 answers

printf ( , ), , , - . . sprintf , .

( ), . ( join)

$result . sprintf(...)

, . , , $result, ,

$result = $result . sprintf(...);

$result .= sprintf(...);
+8

, "try sprintf", , , . , , perl, python ruby?

my $foo = sprintf("%-30s %18s %18s\n", "$a", "$b", "$c\n");
$result .= $foo;
+1

All Articles