You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Nate Smith <na...@thebackrow.net> on 2004/06/08 00:19:21 UTC

Subroutine problem

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;
-]
   <table width="100%" border=1 cellspacing=2 cellpadding=2 align="center">
    <tr>
     <td colspan="7">
       <table width="100%" border=0 cellspacing=0 cellpadding=0 align="center">
        <tr>
         <td align="center">  </td>
         <td align="center"> <font size=4> [+ $months[$m] +] </font></td>
         <td align="center">  </td>
        </tr>
       </table>
     </td>
    </tr>

   <tr>
   [$ foreach $dow @days $]
     <td align="center"> [+ $days[$dow] +] </td>
   [$ endforeach $]
   </tr>

   [$ foreach $week @{$month} $]
      <tr>
      [$ foreach $day @{$month[$week]} $]
        <td> [+ $month[$week][$day]{d} +] </td>
      [$ endforeach $]
      </tr>
   [$ endforeach $]
   </table>

[$ endsub $]

<snip out HTML>

[-  month_cal('2004','6') -]

<more HTML snipped>

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 

Re: Subroutine problem

Posted by Kee Hinckley <na...@somewhere.com>.
At 3:19 PM -0700 6/7/04, Nate Smith wrote:
>[$ sub month_cal $]
>
>[-
>   my ($y, $m) = @_;
>
>   my @months = qw('' January February March
>                April May June July
>                August September October
>                November December);

This declares a local variable for the scope of the [-

>    [$ foreach $dow @days $]

This refers to a page-global variable.

At the top of your page, put
	[$ var @days $]
(and add the other variables)

-- 
Kee Hinckley
http://www.messagefire.com/         Next Generation Spam Defense
http://commons.somewhere.com/buzz/  Writings on Technology and Society

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org