Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: one liner automagic strftime()

by hdb (Monsignor)
on Aug 22, 2017 at 13:07 UTC ( #1197799=note: print w/replies, xml ) Need Help??


in reply to one liner automagic strftime()

In the substitution operator the right hand side is evaluated in scalar context and thus localtime returns the formatted date as a string as per documentation:

use strict; use warnings; my @x = localtime 1503403724; print "@x\n"; my $x = localtime 1503403724; print "$x\n"; my $z = "ccc"; $z =~ s/ccc/wantarray()?"list":"scalar"/e; print "$z\n";

Replies are listed 'Best First'.
Re^2: one liner automagic strftime()
by seki (Scribe) on Aug 23, 2017 at 13:03 UTC

    Arf. So no magic, just the list / scalar context. I have always missed that paragraph of the localtime() perldoc... Thanks.

    The best programs are the ones written when the programmer is supposed to be working on something else. - Melinda Varian

      Difficult to say as "Any sufficiently advanced technology is indistinguishable from magic." (Arthur C. Clarke)

      Perl surely falls into that category...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1197799]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-05-16 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (63 votes). Check out past polls.

    Notices?