Many languages have printf statements ... and yet from a computer scientist's viewpoint, printf is a flawed function. In order for code to be clean and re-usable, functions should be designed to perform a single task. Alas, printf performs two tasks - it both formats the information that's entered in to it AND it then sends that information to an output stream.
What's the better alternative? Where you have printf, you probably have sprintf as well and that's a much better function - it just returns you the formatted string. So I'm advocating that, in Perl for example, you should write:
$tstring = sprintf("%02d:%02d",$hour,$min);
print ("Ths time of this record was $tstring\n"); (written 2006-02-22, updated 2006-06-05)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P207 - Perl - File Handling [12] How many people in a room? - (2004-08-12)
[114] Relative or absolute milkman - (2004-11-10)
[255] STDIN, STDOUT, STDERR and DATA - Perl file handles - (2005-03-23)
[618] Perl - its up to YOU to check your file opened - (2006-02-23)
[702] Iterators - expressions tha change each time you call them - (2006-04-27)
[867] Being sure to be positive in Perl - (2006-09-15)
[1312] Some one line Perl tips and techniques - (2007-08-21)
[1416] Good, steady, simple example - Perl file handling - (2007-10-30)
[1442] Reading a file multiple times - file pointers - (2007-11-23)
[1467] stdout v stderr (Tcl, Perl, Shell) - (2007-12-10)
[1709] There is more that one way - Perl - (2008-07-14)
[1841] Formatting with a leading + / Lua and Perl - (2008-10-15)
[1860] Seven new intermediate Perl examples - (2008-10-30)
[1861] Reactive (dynamic) formatting in Perl - (2008-10-31)
[2233] Transforming data in Perl using lists of lists and hashes of hashes - (2009-06-12)
[2405] But I am reading from a file - no need to prompt (Perl) - (2009-09-14)
[2818] File open and read in Perl - modernisation - (2010-06-19)
[2821] Chancellor George Osborne inspires Perl Program - (2010-06-22)
[2833] Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27)
[3326] Finding your big files in Perl - design considerations beyond the course environment - (2011-06-14)
[3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
[3830] Traversing a directory in Perl - (2012-08-08)
[3839] Spraying data from one incoming to series of outgoing files in Perl - (2012-08-15)
H109 - PHP - Input / Output [653] Easy feed! - (2006-03-21)
[709] Handling huge data files in PHP - (2006-05-04)
[997] Most recent file in a directory - PHP - (2006-12-18)
[1094] PHP fread - truncated data - (2007-02-27)
[1096] Sample script - FTP to get a file from within PHP - (2007-03-01)
[1113] File and URL reading in PHP - (2007-03-20)
[1780] Server overloading - turns out to be feof in PHP - (2008-09-01)
[2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (2010-09-21)
[3029] PHP data sources - other web servers, large data flows, and the client (browser) - (2010-11-04)
[3159] Returning multiple values from a function call in various languages - a comparison - (2011-02-06)
[3424] Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP - (2011-09-08)
[4483] Moving from mysql to mysqli - simple worked example - (2015-05-03)
Some other Articles
Familiar names, close to homeIf its Sunday, it must be the NorlandEasy, Free, Reliable internet accessprintf - a flawed but useful functionLooking for leading not bleeding edgeNews in IrelandGreetings from DublinComing or going?Look out for the motor cyclist