I need to convert the mm/dd ranges such as 0112 - 0402 into the filenames testnnn.txt where nnn = 012 for jan 12th, thru 092 for April 2nd, etc. Year is irrelevant, & leap year can be hard coded in the shortterm, since this will not be used past 2020. I've digressed to the following code, & it appears to work...
sub conv2jul { my $moda=shift; my @Days = (0,31,28,31,30,31,30,31,31,30,31,30,31); if ($leapyear) { $Days [2] = 29; } my $jul = 0; my $i = 0; my $mo = substr($moda,0,2); my $da = substr($moda,2,2); if (($mo <= 0) || ($mo > 12)) { return "000"; } if (($da <= 0) || ($da > 31)) { return "000"; } for ($i = 0;$i < $mo;$i++) { $jul += $Days[$i]; } $jul += $da; return $jul; }
But I started with this & I'm curious as to why it doesn't work...
sub conv2jul { my $moda=shift; my @Days = (0,31,28,31,30,31,30,31,31,30,31,30,31); if ($leapyear) { $Days [2] = 29; } my $jul = 0; my $i = 0; my $mo = substr($moda,0,2); my $da = substr($moda,2,2); if (($mo <= 0) || ($mo > 12)) { return "000"; } if (($da <= 0) || ($da > 31)) { return "000"; } $jul += ($Days[$mo..$mo-1]) + $da; # his is the only diff return $jul; }
I've tried several variation of this syntax, & I always get 0 returned in $jul. Is the range op just not usable in this scenario? More likely I've just hosed it beyond belief ;-) If you can see what I'm trying to accomplish & can offer any enlightenment I'd be very thankful.

In reply to Very Simple Conversion of Gregorian to Julian Calendar by Aim9b

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.