data67 has asked for the wisdom of the Perl Monks concerning the following question:

Here is the deal, I am passing a parameter to this program form a form i.e., FY01, CY01 etc. (where FY= fiscal year and CY = calendar year). The problem is that when I try to get the program to get me output for a specific date range, it's acting weird and the output is not falling in the given range. The second question I had was that if I select "calendar year" in the form I don't want it to still rearrange in "fiscal year" format (e.g., q1, q2, …). This is running with "w" on and i can't use strict.
#TEST By FY or CY### my $go = param('go'); if ($go eq "FY02") { $sdate = "2001/06/01" && $edate = "2002/05/31"; } elsif ($go eq "CY02") { $sdate = "2002/01/01" && $edate = "2002/12/31"; } elsif ($go eq "FY01") { $sdate = "2000/06/01" && $edate = "2001/05/31"; } elsif ($go eq "CY01") { $sdate = "2001/01/01" && $edate = "2001/12/31"; } elsif ($go eq "FY00") { $sdate = "1999/06/01" && $edate = "2000/05/31"; } else { $sdate = "2000/01/01" && $edate = "2000/12/31"; } @ofld = ("?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", " +?", "?", "?", "?", "?"); foreach $line (@loads) { @flds = split (/!/, $line, 17); next if $sdate lt $flds[$DTE] && $flds[$DTE] lt $edate; + #date range foreach $field (@flds) { $field =~ s/\s+$//; if ($field =~ m!(....)/(..)/(..)!) { #r +eorg. date style $field = "$2/$3/$1"; } } $flds[1] = $syst{$flds[1]} || $flds[1]; { my ($m, $d, $y) = split (m!/!, $flds[$DTE]); + #take date and strip "/" my $fq = int (($m + 6) % 12 / 3) % 4 + 1; # +get fiscal quarter my $fy = $y + ($m > 5 ? 1 : 0); #ge +t fiscal year $flds[$VIR] = sprintf "FY %04d Quarter %d", $fy, $fq; + #assign to virtual field } &test_break (); print "<tr valign=\"top\">\n"; foreach $spec (@$OUTPUT) { | | | } }

Replies are listed 'Best First'.
Re: Another Date related quest
by mitd (Curate) on Sep 11, 2001 at 00:42 UTC
    Date::Calc will be your friend.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

      I am somewhat familiar with Date::Calc but I had something else in mind. I want to try it without loading that module for now if all else fails maybe then.
Re: Another Date related quest
by derby (Abbot) on Sep 11, 2001 at 03:58 UTC
    Data

    It's kinda hard to tell from your snippet (trying to figure out what's the base snippet is always a pain) because you haven't shown the loading of $OUTPUT. I'm not seeing much in here that is wrong. Have you tried breaking down your script even more? I'm thinking maybe this line

    next if $sdate lt $flds[$DTE] && $flds[$DTE] lt $edate;

    may not be doing what you want. Have you tried removing the guts of the script and just outputting $flds[$DTE] so you can see what's happening? If you're using CGI.pm, have you tried to "offline" debug it?

    -derby