Perl sprintf 函式



描述

此函式使用 FORMAT 針對 LIST 中的值返回格式化字串。和 printf 基本相同,只不過格式化字串會傳回而非列印出來。

語法

以下是此函式的簡單語法 −

sprintf FORMAT, LIST

返回值

此函式返回 SCALAR,即格式化文字字串。

示例

以下是顯示其基本用法的示例程式碼 −

#!/usr/bin/perl -w

$text = sprintf("%0d \n", 9);

print "Formated string $text\n";

執行以上程式碼後,將產生以下結果 −

Formated string 9 
perl_function_references.htm
廣告
© . All rights reserved.