This reply is hard for me to understand. The whole idea of this is to set the $yr and $day, etc. variables!

my (undef, $min, $hr, $day, $mon, $year) = localtime();
and
my ($min, $hr, $day, $mon, $year) = (localtime())[1..5];
mean exactly the same thing.

Perhaps one point of confusion is that your statements like my $year; are completely unnecessary. That creates the variable $year and assigns it the value of undef. In general, combine the creation of the variable and the assignment of useful value to it into one statement. There is no need to have a list of my $year; type of statements before assigning values to them. Also limit the use of these newly created "my" variables to the smallest scope practical.

In general, $_ , the "default variable", "belongs to Perl" - meaning that is something Perl sets and you read, but you never set or write to yourself. There are of course exceptions to this. However, for your first few hundred programs, you are unlikely to happen across one of these exceptions.


In reply to Re^3: how can I get localtime without mutating any variables by Marshall
in thread how can I get localtime without mutating any variables by thirtySeven

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.