#!/usr/bin/perl -w
#one map one location.
#####################format transfer char
#%b ==> non symbol binary integer
#%c ==> char
#%d %i ==> decimal integer
#%e ==> scientific count
#%E ==> scientific count with E
#%f %F ==> float number
#%g ==> fetch min width, using e or f transfer char
#%G ==> fetch max width, using e or f transfer char
#%id %D ==> long decimal integer
#%lu %U ==> non symbol long decimal integer
#%lo %O ==> long octal integer
#%p ==> pointer (hexadecimal)
#%s ==> string
#%u ==> non symbol decimal number
#%x ==> hexadecimal number
#%X ==> hexadecimal number, using UPPER X
#%1x ==> hexadecimal long integer
#%% ==> print %
#%o ==> octal integer
#
######################mark decorate char
#%- ==> left aligning (default is right aligning)
#%# ==> "0" leading char for octal, and "0x" for hexadecimal
#%+ ==> use d e f g transfer char, display part of integer, and positive and negative
#%0 ==> replace the blank to zero 0
#%number ==> maximum column width, like %6d
#%.number ==> the precision of float number, like %.2f like %4.2 ==> 33.33
#$s ==> conversion character, $d ==> decimal output
#
########example:
printf("The name is %s and the number is %d\n", "John",50);
printf "Hello to you and yours %s \n", "Sam McGoo!"; #string
printf ("%-15s %20s \n","Jack \n", "Sprat \n"); #left aligning and right aligning
printf "The number in decimal is %d \n", 45; #45
printf "The formatted number is | %10d | \n" , 100; #" 100"
printf "The number printed with leading zeros is | %010d | \n", 5;
#%0 => replace to 0, 10 => max width , d => decimal integer
printf "Left-justified the number is | %-10d | \n", 100; #left aligning and 10 maximum
printf "The number in octal is %o\n",15; #17 ==> 8+7=15
printf "The number in hexadecimal is %x \n", 15; #f ==> 16-1=15 hexadecimal
printf "The formatted floating point number is | %8.2f | \n", 14.3456; #14.35
printf "The floating point number is | %8f | \n", 15; # 15.000000
printf "The character is %c\n", 65; #A ascii(65) ==> A
######sprintf for var
$string = sprintf("The name is: %10s\n The number is: %8.2f \n", "Ellie", 33);
print "$string";
#The name is: Ellie
# The number is: 33.00
#####like shell text compution
$price=1000;
#enable var quotes
print <<EOF;
The consumer commented, "As I look over my budget,
I'd say the price of $price is right. I'll give you \$500 to start."\n
EOF
#disable var quotes.
print <<'FINIS';
The consumer commented, "As I look over my budget,
I'd say the price of $price is too much.\n I'll settle for $500."
FINIS
#run the os commands use backquotes.
print "\nLet's execute some commands.\n";
print <<`END`;
echo "Today is"
date
END
perl printf
原创emperor_majesty 博主文章分类:Perl ©著作权
文章标签 perl printf function 文章分类 运维
上一篇:perl print01
下一篇:Sed Get Code

-
C语言printf和scanf详细介绍
详细介绍了C语言prinf和scanf的使用和各种参数
占位符 #include 字符串 -
java printf 菜鸟 java printf %n
目前printf支持以下格式: %c 单个字符 %d  
java printf 菜鸟 System 字符串 整型 -
java printf 输出 java中printf
目前printf支持以下格式: %c 单个字符 %d 十进制整数 %f 十进制浮点数 %o 八进制数 &n
java printf 输出 java string jdk class