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

use Math::RungeKutta; sub outer { my $var = sub_from_other_package(); my $differ = sub { my $y = shift; $var->[...]{...}{...}; etc. ... return $res; }; my $dydt = sub { my ($t,@y) = @_; return $differ->($y); }; ($t, @y) = rkXXX(\@y, $dydt, $t, $dt); }

Replies are listed 'Best First'.
Re^5: Closures and undefined subs
by Anonymous Monk on Sep 26, 2007 at 17:22 UTC
    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.

      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.