Return-Path: Delivered-To: apmail-perl-embperl-archive@www.apache.org Received: (qmail 15505 invoked from network); 7 Jun 2004 23:20:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Jun 2004 23:20:39 -0000 Received: (qmail 74634 invoked by uid 500); 7 Jun 2004 23:20:42 -0000 Delivered-To: apmail-perl-embperl-archive@perl.apache.org Received: (qmail 74615 invoked by uid 500); 7 Jun 2004 23:20:42 -0000 Mailing-List: contact embperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list embperl@perl.apache.org Received: (qmail 74586 invoked by uid 99); 7 Jun 2004 23:20:42 -0000 Received: from [64.152.73.80] (HELO leftcoast.thebackrow.net) (64.152.73.80) by apache.org (qpsmtpd/0.27.1) with ESMTP; Mon, 07 Jun 2004 16:20:42 -0700 Received: from nate by leftcoast.thebackrow.net with local (Microsoft Exchange Internet Mail Service 5.5.2653.13) for ; Mon, 07 Jun 2004 15:19:21 -0700 Date: Mon, 7 Jun 2004 15:19:21 -0700 To: embperl@perl.apache.org Subject: Subroutine problem Message-ID: <20040607221921.GS1621@thebackrow.net> Reply-To: Nate Smith Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline User-Agent: Mutt/1.5.5.1+cvs20040105i From: Nate Smith X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I've read through the docs and the archive to no avail.. I'm creating a calendar with some functions like this: sub get_week{ local ($y, $m, $d) = @_; local %week = (); # HoH's for our week local $dotw = Day_of_Week($y, $m, $d); local ($monday_y, $monday_m, $monday_d) = Add_Delta_Days($y, $m, $d, -($dotw-1)); for (my $i=0; $i<7; $i++) { local ($week[$i]{'y'}, $week[$i]{'m'}, $week[$i]{'d'}) = Add_Delta_Days($monday_y, $monday_m, $monday_d, $i); } return \@week; } sub get_month{ local ($y, $m) = @_; local $ditm = Days_in_Month($y, $m); local @month = (); local $d = 1; WEEK: for(my $i=0; $i<=5; $i++) { $month[$i] = get_week($y, $m, $d); last WEEK if (($month[$i][6]{m} > $m) || ($month[$i][6]{y} > $y)); $d = ( (($d+7) > $ditm) ? ($ditm) : ($d+7) ); } return \@month; } so that my page looks something like this: [- +-- 18 lines: sub get_week{---- (see above) +-- 21 lines: sub get_month{--- (see above) -] [$ sub month_cal $] [- my ($y, $m) = @_; my @months = qw('' January February March April May June July August September October November December); my @days = qw(Mon Tue Wed Thu Fri Sat Sun); $month = get_month($y, $m); #print OUT Dumper \$month; -] [$ foreach $dow @days $] [$ endforeach $] [$ foreach $week @{$month} $] [$ foreach $day @{$month[$week]} $] [$ endforeach $] [$ endforeach $]
[+ $months[$m] +]
[+ $days[$dow] +]
[+ $month[$week][$day]{d} +]
[$ endsub $] [- month_cal('2004','6') -] Now, the output from Data::Dumper looks like: $VAR1 = \[ [ {}, {}, {}, {}, {}, {}, {} ], ${$VAR1}->[0], ${$VAR1}->[0], ${$VAR1}->[0], ${$VAR1}->[0], ${$VAR1}->[0] ]; with no values. I have a test script working correctly, also attached. This is the same code, cut/pasted and embperl'd. Anybody have any idea why I can't do something like this? I'm calling an Embperl function which calls another function, which in turn calls one other function 4-5 times, to build a data structure of the days that should appear on a calendar. Help! Nate Smith --YiEDa0DAkWCtVeE4 Content-Type: text/x-perl; charset=us-ascii Content-Disposition: attachment; filename="test.pl" #!/usr/bin/perl # use strict; use Date::Calc qw(:all); # my $y = 2004; # for (my $m=1; $m<=12; $m++){ my ($y, $m, $d) = (localtime(time))[5,4,3]; $y+= 1900; $m++; get_month ($y,$m); my $month = get_month($y, $m); for(my $week=0; $week<@{$month}; $week++) { print "$m/$y Week $week : \n"; for(my $day=0; $day<@{${$month}[$week]}; $day++) { print "${$month}[$week][$day]{dayname}, ${$month}[$week][$day]{m}/${$month}[$week][$day]{d}/${$month}[$week][$day]{y}\n"; } print "\n"; } #} sub get_month { my ($y, $m) = @_; # How many Days In This Month? my $ditm = Days_in_Month($y, $m); # month: an Array of Arrays? my @month = (); # Now get the weeks.. my $d = 1; WEEK: for(my $i=0; $i<=5; $i++) { $month[$i] = get_week($y, $m, $d); last WEEK if (($month[$i][6]{m} > $m) || ($month[$i][6]{y} > $y)); $d = ( (($d+7) > $ditm) ? ($ditm) : ($d+7) ); } return \@month; } sub get_week { my ($year, $month, $day) = @_; my @week = (); my $dotw = Day_of_Week($year, $month, $day); my ($monday_y, $monday_m, $monday_d) = Add_Delta_Days($year, $month, $day, -($dotw-1)); for (my $i=0; $i<7; $i++) { ($week[$i]{'y'}, $week[$i]{'m'}, $week[$i]{'d'}) = Add_Delta_Days($monday_y, $monday_m, $monday_d, $i); my $dotw = Day_of_Week($week[$i]{'y'}, $week[$i]{'m'}, $week[$i]{'d'}); $week[$i]{'dayname'} = ('','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')[$dotw]; } return \@week; } --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org For additional commands, e-mail: embperl-help@perl.apache.org --YiEDa0DAkWCtVeE4--