Programming C# C++ (7) Delphi (618) Java (8) JavaScript (30) perl (9) mysql (3) perl CGI (3) php (4) VBScript (1) Visual Basic (1)
Exchange Links About this site Links to us 
|
Obtaining the time and time in different formats
This article has not been rated yet. After reading, feel free to leave comments and rate it.
The localtime function is described in the perlfunc.pod as: "[converting] a time as returned by the time function to a 9-element array with the time analyzed for the local time zone." It returns different values, depending on whether it is called in list or scalar context.
Using it as an argument to the print function, which takes its arguments in list context, returns an array of values. Therefore, it is similar to printing an array or list. You will get a concatenated string of numbers as each element of print's argument list is stringified before printing. (You can use the join function to separate the values. See example with next paragraph.)
Assigning the result of the function to a scalar, or forcing scalar context with the scalar operator, will return a date/time string. Similarly, using the substr() function (to get a substring) is also scalar context. The line containing 'substr' below gets the 1st 3 chars of localtime's scalar context returned string:
 | |  | | print localtime();
print join (" ",localtime() );
print scalar localtime();
$datetime = localtime();
print $datetime;
| |  | |  |
Comments:
|