On 7/4/19 2:41 PM, Mike Small wrote:
A co-worker was trying to take some of the elements from gmtime's return
value. He did something like the following:

$ perl -E'$,="\t";say gmtime[1..5]'

that is calling gmtime with the argument of [1..5] which is an arrayref. so the arg to gmtime is some large address number. it is then parsed as the timestamp and broken out. garbage in, garbage out!
8       32      12      31      7       2999416 1       243     0

I suggested he try something like this instead...

$ perl -E'$,="\t";say ((gmtime)[1..5])'
36      18      4       6       119
here gmtime is called with no args as it is in parens. so it uses the value of time() which is what he wanted.

... and that was what he wanted, but it didn't matter because he
re-rewrote his code to use strftime, which we both thought was more
readable.  But still, what are those numbers in the first example?
Neither of us can figure where they come from. The parens must be a
clue, but all I could think was gmtime was interpreted as an array
reference, but thinking that didn't get me anywhere that made sense to
me.
it is an array ref. but it is used as the epoch time and it is wacky for that.

uri

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to