in reply to Re^4: Closures and undefined subs
in thread Closures and undefined subs

Will try it out tomorrow. Original code of the whole module (but it needs other 3 not posted and the original main programme) was posted as answer for your demand for original code a bit earlier.

Replies are listed 'Best First'.
Re^6: Closures and undefined subs
by ikegami (Patriarch) on Sep 26, 2007 at 17:30 UTC

    I didn't ask for the original code. Quite the opposite. I asked for the code giving the error. What you posted doesn't demonstrate the problem, so its useless. We can't debug code we don't see.

      OK. Then how about this?
      package Levels::Level_IV; use strict; use warnings; use Math::RungeKutta; ... sub level_iv { my ( $args_ref, $R, $factor, $level_iii_ref ) = @_; ... for my $i ( $t..$t_final ) { ... ( $t, $dt, @y_med ) = rk4_auto( \@y_med, \&_dydt, $t, $dt, $eps + ); } ... sub _equation_air { my ( $args_ref, $level_iii_ref, $y ) = @_; #I tried these options # # my $_equation_air = sub { # my $y = shift; # local *_equation_air = sub { # my $y = shift; #for easy calculations make copies of the parameters (not alia +ses) my arguments for formula from $args_ref and $level_iii_ref #differential equation for mass my $dydt = some formula; return $dydt; }; ... #differential equation for fugacity at start and end times sub _dydt { my ( $t, @y ) = @_; my @dydt; #start differentiation at point y0 (air) $dydt[0] = _equation_air( $args_ref, $level_iii_ref, $y[0] ); #tried these #$dydt[0] = _equation_air($y[0]); #local #$dydt[0] = $_equation_air->($y[0]);#lexical ... return @dydt; } ... return some hash; }
      Failures are described in another post earlier if I try lexical or local.

        That's the original code still!! We have already told you how to fix it, and it does not give the errors you want us to look at.

        However, I think I guessed what you are doing wrong: setting local *func or my $func after the point where it's used.

        # BAD sub outer { my $var; ($t, @y) = rkXXX(\@y, $dydt, $t, $dt); my $dydt = sub { ... }; } # Good sub outer { my $var; my $dydt = sub { ... }; ($t, @y) = rkXXX(\@y, $dydt, $t, $dt); }