in reply to Can a large subroutine be split in two (e.g. parent and child relationship)?

If I'm understanding it right, you have something like this:

sub foo { my ($var1, $var2, $var3, @arr1); [a large pile of code] }

And you vant to split that code in two smaller subs but are worried about variable scoping and so. What about this?

{ my ($var1, $var2, $var3, @arr1); sub foo { [some code] bar(); } sub bar { [rest of the code] } }

--
David Serrano

Replies are listed 'Best First'.
Re^2: Can a large subroutine be split in two (e.g. parent and child relationship)
by GrandFather (Saint) on Jul 05, 2006 at 21:04 UTC

    That creates a closure on the variables which is different behaviour than having the variables local to $foo. Consider:

    use strict; use warnings; { my ($var1, $var2, $var3, @arr1); sub foo { bar(); } sub bar { ++$var1; print "$var1\n"; } } foo (); foo ();

    Prints:

    1 2

    DWIM is Perl's answer to Gödel
      That creates a closure on the variables

      It was intended but now I realize that I didn't take into account the outcome you are showing.

      --
      David Serrano