perl CGI (9)
Visual Basic (3539)
About this site
Links to us
General :: Programming :: perl
General questions about perl.
This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Generated 0:01:41 on Oct 24, 2020
Obtaining the time and time in different formats
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 join (" ",localtime() );
print scalar localtime();
$datetime = localtime();
|Most recent comments