I'm looking to create a definable timestamp from the value of localtime and I realised I needed to zero pad several values to make the timestamps numerically sortable.
If your goal is to sort dates, then you can actually skip the localtime conversion and just take "time" which gives you an integer, and pad it with zeros and sort that or just sort them as numbers. You don't have to create a timestamp or use localtime to break up the time into years, months, days, hours, minutes, and seconds. If your program saves the time by recording whatever "time" returns, then you can sort those integers very easily. You might not even have to zero pad them, just do:
my @times = ... # list of times
@times = sort {$a <=> $b} @times;
Note: The "time" function returns the number of seconds since Jan 1, 1970 except on MacOS, where it returns the seconds since Jan 1, 1904.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.