Re: What are these numbers (gmtime, slice)

2019-07-08 Thread Mike Small
Uri Guttman  writes:

> 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!

Thanks Uri! That makes perfect sense now that I see it explained.

-- 
Mike Small
sma...@sdf.org

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




What are these numbers (gmtime, slice)

2019-07-07 Thread Mike Small
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]'
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

... 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.

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