Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report