Get the App
SLTechnology News&Howtos  ›  Development  › 

Detailed explanation of print, printf and sprintf use cases of perl

Shulou Source: shulou.com Published: 2022-06-03 20:16:01 10月04日 Update

This article introduces the relevant knowledge of "detailed explanation of print, printf and sprintf use cases of perl". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Catalogue

Print

Printf

Sprintf

Difference

For more information on usage, you can check the perl user manual.

Perldoc-f print

Perldoc-f printf

Perldoc-f sprintf

They each support three or four command formats. But only one or two are commonly used.

Print

Commonly used:

Print LIST

Print FILEHANDLE LIST

It is not commonly used (mainly because implicit details can lead to reading difficulties):

Print FILEHANDLE

Print

Print $foo;print "Hello $world"; print $filehandle $something;printf

Commonly used:

Printf FORMAT, LIST

Printf FILEHANDLE FORMAT, LIST

It is not commonly used (mainly because implicit details can lead to reading difficulties):

Printf FILEHANDLE

Printf

Printf'This is question% d on% slots, 36882022, 'StackOverflow';sprintf

There is only one command format:

Sprintf FORMAT, LIST

$result = sprintf ('The% s is% dwells,' answer', 42)

In addition, there are many complex uses of sprinf, which are not commonly used by individuals. Refer to perldoc-f sprintf for details.

For example:

Printf'% 2$ d% 1$ commanddescriptionprint, 12, 34; # prints "34 12" printf'% 3$ d% 1$ d, 1, 2, 3; # prints "3 1 1" distinguishes the commanddescriptionprint print information and can be output to a file in a format in which printf can organize the information. Similar to sprintf, the difference is that you can print the format in which sprintf can organize the information. Similar to printf, the difference is that it is only used for string formatting, without any print effect. "perl print, printf, sprintf use case details" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Commonly used format case information output content commands files more knowledge details obstacles complex practical successful learning and then individuals only dilemmas characters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker Microsoft Shulou Tech Info MySQL