Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: The day of today

by haoess (Curate)
on Mar 07, 2008 at 12:19 UTC ( #672749=note: print w/ replies, xml ) Need Help??


in reply to The day of today

perl -le 'print +(localtime)[3]'

Runs under strict too.

-- Frank


Comment on Re: The day of today
Download Code
Replies are listed 'Best First'.
Re^2: The day of today
by grinder (Bishop) on Mar 07, 2008 at 13:16 UTC

    This example confuses the issue. One might conclude that the + (plus) is necessary, when in fact it's not. It's only there to workaround print's brain-damage. It could be written less ambiguously as:

    my $dayOfMonth = (localtime)[3]; print "Today is day $dayOfMonth.";

    Note to gtrain: this is technically known as an array slice. You are taking the array of values returned by localtime and slicing out only the fourth (offset 3) element).

    • another intruder with the mooring in the heart of the Perl

      my $dayOfMonth = (localtime)[3];
      In Perl terminology this is not an array slice, a slice would contrain contain more than one element . An array slice expresses a list, not a scalar. An array slice expresses a list, not an array.

      Be well,
      rir

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2015-07-28 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls