Aim9b has asked for the wisdom of the Perl Monks concerning the following question:
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"; } for ($i = 0;$i < $mo;$i++) { $jul += $Days[$i]; } $jul += $da; 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.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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Very Simple Conversion of Gregorian to Julian Calendar
by almut (Canon) on Aug 22, 2007 at 13:01 UTC | |
|
Re: Very Simple Conversion of Gregorian to Julian Calendar
by moritz (Cardinal) on Aug 22, 2007 at 12:15 UTC | |
|
Re: Very Simple Conversion of Gregorian to Julian Calendar
by FunkyMonk (Bishop) on Aug 22, 2007 at 12:47 UTC | |
|
Re: Very Simple Conversion of Gregorian to Julian Calendar
by Fletch (Bishop) on Aug 22, 2007 at 12:59 UTC |