Perl Passing Function as an Argument - Undefined Sub Reference












0















I'm reading the book "Higher Order Perl" by Mark Jason Dominus and I'm stuck on one of the first examples. It revolves around solving the Tower of Hanoi problem recursively, which my program does fine. The problem is, the book develops the example by refactoring the code, where rather than simply printing what the solution is doing, the solution function takes another parameter. This is a function that in my case simply does the same thing.



The problem is, I have defined my auxiliary function and I've attempted to pass it by reference, and then call it from the main function, but I am getting the following error.




Can't use an undefined value as a subroutine reference at main.pl line 86.




This version does not take a function as an argument and correctly solves the problem.



#!/usr/bin/perl

use utf8;
use v5.26;

use strict;
use warnings;

sub SolveTowerOfHanoiProblem0 {
my ($n, $start, $end, $extra) = @_;

if ($n == 1) {
say "Move disk #$n from $start to $end.";
} else {
SolveTowerOfHanoiProblem0($n - 1, $start, $extra, $end);

say "Move disk #$n from $start to $end.";

SolveTowerOfHanoiProblem0($n - 1, $extra, $end, $start);
}
}

SolveTowerOfHanoiProblem0(3, 'A', 'C', 'B');


Output:



Move disk #1 from A to C.
Move disk #2 from A to B.
Move disk #1 from C to B.
Move disk #3 from A to C.
Move disk #1 from B to A.
Move disk #2 from B to C.
Move disk #1 from A to C.


I want to refactor the code to have the line that outputs what is happening in each step to be independent of the solution code, so for the time being I wrote another function that simply does the same thing, but is passed as an argument by the caller:



sub SolveTowerOfHanoiProblem {
my ($n, $start, $end, $extra, $moveDisk) = @_;

if ($n == 1) {
$moveDisk->($n, $start, $end);
} else {
SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

$moveDisk->($n, $start, $end);

SolveTowerOfHanoiProblem($n - 1, $extra, $end, $start);
}
}

sub PrintInstruction {
my ($disk, $start, $end) = @_;

say "Move disk #$disk from $start to $end.";
}


SolveTowerOfHanoiProblem(8, 'A', 'C', 'B', &PrintInstruction);


I am getting the following runtime error: Can't use an undefined value as a subroutine reference at main.pl line 86. This is where I call the passed-in function for the first time.



Line 86:



if ($n == 1) {
$moveDisk->($n, $start, $end); # <---- Here, Line 86
} else {
SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

$moveDisk->($n, $start, $end);


I don't understand why the sub reference would be undefined. I've defined the function I'm referencing, and from what I've found so far (PerlMonks - Call subroutine by reference ?) I seem to be calling the function correctly.



I've looked at this question as well, but my PrintInstruction function isn't defined in a module, it's defined locally, so if I understand correctly I don't need the $ symbol in the reference.



What am I missing?










share|improve this question



























    0















    I'm reading the book "Higher Order Perl" by Mark Jason Dominus and I'm stuck on one of the first examples. It revolves around solving the Tower of Hanoi problem recursively, which my program does fine. The problem is, the book develops the example by refactoring the code, where rather than simply printing what the solution is doing, the solution function takes another parameter. This is a function that in my case simply does the same thing.



    The problem is, I have defined my auxiliary function and I've attempted to pass it by reference, and then call it from the main function, but I am getting the following error.




    Can't use an undefined value as a subroutine reference at main.pl line 86.




    This version does not take a function as an argument and correctly solves the problem.



    #!/usr/bin/perl

    use utf8;
    use v5.26;

    use strict;
    use warnings;

    sub SolveTowerOfHanoiProblem0 {
    my ($n, $start, $end, $extra) = @_;

    if ($n == 1) {
    say "Move disk #$n from $start to $end.";
    } else {
    SolveTowerOfHanoiProblem0($n - 1, $start, $extra, $end);

    say "Move disk #$n from $start to $end.";

    SolveTowerOfHanoiProblem0($n - 1, $extra, $end, $start);
    }
    }

    SolveTowerOfHanoiProblem0(3, 'A', 'C', 'B');


    Output:



    Move disk #1 from A to C.
    Move disk #2 from A to B.
    Move disk #1 from C to B.
    Move disk #3 from A to C.
    Move disk #1 from B to A.
    Move disk #2 from B to C.
    Move disk #1 from A to C.


    I want to refactor the code to have the line that outputs what is happening in each step to be independent of the solution code, so for the time being I wrote another function that simply does the same thing, but is passed as an argument by the caller:



    sub SolveTowerOfHanoiProblem {
    my ($n, $start, $end, $extra, $moveDisk) = @_;

    if ($n == 1) {
    $moveDisk->($n, $start, $end);
    } else {
    SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

    $moveDisk->($n, $start, $end);

    SolveTowerOfHanoiProblem($n - 1, $extra, $end, $start);
    }
    }

    sub PrintInstruction {
    my ($disk, $start, $end) = @_;

    say "Move disk #$disk from $start to $end.";
    }


    SolveTowerOfHanoiProblem(8, 'A', 'C', 'B', &PrintInstruction);


    I am getting the following runtime error: Can't use an undefined value as a subroutine reference at main.pl line 86. This is where I call the passed-in function for the first time.



    Line 86:



    if ($n == 1) {
    $moveDisk->($n, $start, $end); # <---- Here, Line 86
    } else {
    SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

    $moveDisk->($n, $start, $end);


    I don't understand why the sub reference would be undefined. I've defined the function I'm referencing, and from what I've found so far (PerlMonks - Call subroutine by reference ?) I seem to be calling the function correctly.



    I've looked at this question as well, but my PrintInstruction function isn't defined in a module, it's defined locally, so if I understand correctly I don't need the $ symbol in the reference.



    What am I missing?










    share|improve this question

























      0












      0








      0








      I'm reading the book "Higher Order Perl" by Mark Jason Dominus and I'm stuck on one of the first examples. It revolves around solving the Tower of Hanoi problem recursively, which my program does fine. The problem is, the book develops the example by refactoring the code, where rather than simply printing what the solution is doing, the solution function takes another parameter. This is a function that in my case simply does the same thing.



      The problem is, I have defined my auxiliary function and I've attempted to pass it by reference, and then call it from the main function, but I am getting the following error.




      Can't use an undefined value as a subroutine reference at main.pl line 86.




      This version does not take a function as an argument and correctly solves the problem.



      #!/usr/bin/perl

      use utf8;
      use v5.26;

      use strict;
      use warnings;

      sub SolveTowerOfHanoiProblem0 {
      my ($n, $start, $end, $extra) = @_;

      if ($n == 1) {
      say "Move disk #$n from $start to $end.";
      } else {
      SolveTowerOfHanoiProblem0($n - 1, $start, $extra, $end);

      say "Move disk #$n from $start to $end.";

      SolveTowerOfHanoiProblem0($n - 1, $extra, $end, $start);
      }
      }

      SolveTowerOfHanoiProblem0(3, 'A', 'C', 'B');


      Output:



      Move disk #1 from A to C.
      Move disk #2 from A to B.
      Move disk #1 from C to B.
      Move disk #3 from A to C.
      Move disk #1 from B to A.
      Move disk #2 from B to C.
      Move disk #1 from A to C.


      I want to refactor the code to have the line that outputs what is happening in each step to be independent of the solution code, so for the time being I wrote another function that simply does the same thing, but is passed as an argument by the caller:



      sub SolveTowerOfHanoiProblem {
      my ($n, $start, $end, $extra, $moveDisk) = @_;

      if ($n == 1) {
      $moveDisk->($n, $start, $end);
      } else {
      SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

      $moveDisk->($n, $start, $end);

      SolveTowerOfHanoiProblem($n - 1, $extra, $end, $start);
      }
      }

      sub PrintInstruction {
      my ($disk, $start, $end) = @_;

      say "Move disk #$disk from $start to $end.";
      }


      SolveTowerOfHanoiProblem(8, 'A', 'C', 'B', &PrintInstruction);


      I am getting the following runtime error: Can't use an undefined value as a subroutine reference at main.pl line 86. This is where I call the passed-in function for the first time.



      Line 86:



      if ($n == 1) {
      $moveDisk->($n, $start, $end); # <---- Here, Line 86
      } else {
      SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

      $moveDisk->($n, $start, $end);


      I don't understand why the sub reference would be undefined. I've defined the function I'm referencing, and from what I've found so far (PerlMonks - Call subroutine by reference ?) I seem to be calling the function correctly.



      I've looked at this question as well, but my PrintInstruction function isn't defined in a module, it's defined locally, so if I understand correctly I don't need the $ symbol in the reference.



      What am I missing?










      share|improve this question














      I'm reading the book "Higher Order Perl" by Mark Jason Dominus and I'm stuck on one of the first examples. It revolves around solving the Tower of Hanoi problem recursively, which my program does fine. The problem is, the book develops the example by refactoring the code, where rather than simply printing what the solution is doing, the solution function takes another parameter. This is a function that in my case simply does the same thing.



      The problem is, I have defined my auxiliary function and I've attempted to pass it by reference, and then call it from the main function, but I am getting the following error.




      Can't use an undefined value as a subroutine reference at main.pl line 86.




      This version does not take a function as an argument and correctly solves the problem.



      #!/usr/bin/perl

      use utf8;
      use v5.26;

      use strict;
      use warnings;

      sub SolveTowerOfHanoiProblem0 {
      my ($n, $start, $end, $extra) = @_;

      if ($n == 1) {
      say "Move disk #$n from $start to $end.";
      } else {
      SolveTowerOfHanoiProblem0($n - 1, $start, $extra, $end);

      say "Move disk #$n from $start to $end.";

      SolveTowerOfHanoiProblem0($n - 1, $extra, $end, $start);
      }
      }

      SolveTowerOfHanoiProblem0(3, 'A', 'C', 'B');


      Output:



      Move disk #1 from A to C.
      Move disk #2 from A to B.
      Move disk #1 from C to B.
      Move disk #3 from A to C.
      Move disk #1 from B to A.
      Move disk #2 from B to C.
      Move disk #1 from A to C.


      I want to refactor the code to have the line that outputs what is happening in each step to be independent of the solution code, so for the time being I wrote another function that simply does the same thing, but is passed as an argument by the caller:



      sub SolveTowerOfHanoiProblem {
      my ($n, $start, $end, $extra, $moveDisk) = @_;

      if ($n == 1) {
      $moveDisk->($n, $start, $end);
      } else {
      SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

      $moveDisk->($n, $start, $end);

      SolveTowerOfHanoiProblem($n - 1, $extra, $end, $start);
      }
      }

      sub PrintInstruction {
      my ($disk, $start, $end) = @_;

      say "Move disk #$disk from $start to $end.";
      }


      SolveTowerOfHanoiProblem(8, 'A', 'C', 'B', &PrintInstruction);


      I am getting the following runtime error: Can't use an undefined value as a subroutine reference at main.pl line 86. This is where I call the passed-in function for the first time.



      Line 86:



      if ($n == 1) {
      $moveDisk->($n, $start, $end); # <---- Here, Line 86
      } else {
      SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);

      $moveDisk->($n, $start, $end);


      I don't understand why the sub reference would be undefined. I've defined the function I'm referencing, and from what I've found so far (PerlMonks - Call subroutine by reference ?) I seem to be calling the function correctly.



      I've looked at this question as well, but my PrintInstruction function isn't defined in a module, it's defined locally, so if I understand correctly I don't need the $ symbol in the reference.



      What am I missing?







      perl






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 20:00









      Jose Fernando Lopez FernandezJose Fernando Lopez Fernandez

      555316




      555316
























          2 Answers
          2






          active

          oldest

          votes


















          3














          The SolveTowerOfHanoiProblem function expects a code ref as last (fifth) argument, but you are not passing it when you invoke it in your « else » block :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);


          Should be written as :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end, $moveDisk);





          share|improve this answer
























          • Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

            – Jose Fernando Lopez Fernandez
            Nov 22 '18 at 20:39



















          4














          You are passing the code ref to the original call to SolveTowerOfHanoiProblem, but not to the recursive calls.



          You could simply pass the code ref.



          SolveTowerOfHanoiProblem($n - 1, ..., $moveDisk);


          Or could remove the need to pass the same value over and over again.



          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          local *helper = sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          helper($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          helper($n - 1, $extra, $end, $start);
          }
          };

          helper(@_);
          }


          Same, but using a feature introduced in Perl 5.16:



          use feature qw( current_sub );

          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          __SUB__->($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          __SUB__->($n - 1, $extra, $end, $start);
          }
          }->(@_);
          }





          share|improve this answer


























          • Wow, I hadn't come across nested subroutines like this, thanks for the heads up

            – Jose Fernando Lopez Fernandez
            Nov 24 '18 at 4:27






          • 1





            Just don't nest named subs

            – ikegami
            Nov 24 '18 at 4:29











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437406%2fperl-passing-function-as-an-argument-undefined-sub-reference%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          The SolveTowerOfHanoiProblem function expects a code ref as last (fifth) argument, but you are not passing it when you invoke it in your « else » block :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);


          Should be written as :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end, $moveDisk);





          share|improve this answer
























          • Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

            – Jose Fernando Lopez Fernandez
            Nov 22 '18 at 20:39
















          3














          The SolveTowerOfHanoiProblem function expects a code ref as last (fifth) argument, but you are not passing it when you invoke it in your « else » block :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);


          Should be written as :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end, $moveDisk);





          share|improve this answer
























          • Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

            – Jose Fernando Lopez Fernandez
            Nov 22 '18 at 20:39














          3












          3








          3







          The SolveTowerOfHanoiProblem function expects a code ref as last (fifth) argument, but you are not passing it when you invoke it in your « else » block :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);


          Should be written as :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end, $moveDisk);





          share|improve this answer













          The SolveTowerOfHanoiProblem function expects a code ref as last (fifth) argument, but you are not passing it when you invoke it in your « else » block :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end);


          Should be written as :



          SolveTowerOfHanoiProblem($n - 1, $start, $extra, $end, $moveDisk);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 20:24









          GMBGMB

          8,7172623




          8,7172623













          • Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

            – Jose Fernando Lopez Fernandez
            Nov 22 '18 at 20:39



















          • Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

            – Jose Fernando Lopez Fernandez
            Nov 22 '18 at 20:39

















          Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

          – Jose Fernando Lopez Fernandez
          Nov 22 '18 at 20:39





          Wow, I cannot believe I missed that. Thanks a lot, I appreciate it

          – Jose Fernando Lopez Fernandez
          Nov 22 '18 at 20:39













          4














          You are passing the code ref to the original call to SolveTowerOfHanoiProblem, but not to the recursive calls.



          You could simply pass the code ref.



          SolveTowerOfHanoiProblem($n - 1, ..., $moveDisk);


          Or could remove the need to pass the same value over and over again.



          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          local *helper = sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          helper($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          helper($n - 1, $extra, $end, $start);
          }
          };

          helper(@_);
          }


          Same, but using a feature introduced in Perl 5.16:



          use feature qw( current_sub );

          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          __SUB__->($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          __SUB__->($n - 1, $extra, $end, $start);
          }
          }->(@_);
          }





          share|improve this answer


























          • Wow, I hadn't come across nested subroutines like this, thanks for the heads up

            – Jose Fernando Lopez Fernandez
            Nov 24 '18 at 4:27






          • 1





            Just don't nest named subs

            – ikegami
            Nov 24 '18 at 4:29
















          4














          You are passing the code ref to the original call to SolveTowerOfHanoiProblem, but not to the recursive calls.



          You could simply pass the code ref.



          SolveTowerOfHanoiProblem($n - 1, ..., $moveDisk);


          Or could remove the need to pass the same value over and over again.



          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          local *helper = sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          helper($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          helper($n - 1, $extra, $end, $start);
          }
          };

          helper(@_);
          }


          Same, but using a feature introduced in Perl 5.16:



          use feature qw( current_sub );

          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          __SUB__->($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          __SUB__->($n - 1, $extra, $end, $start);
          }
          }->(@_);
          }





          share|improve this answer


























          • Wow, I hadn't come across nested subroutines like this, thanks for the heads up

            – Jose Fernando Lopez Fernandez
            Nov 24 '18 at 4:27






          • 1





            Just don't nest named subs

            – ikegami
            Nov 24 '18 at 4:29














          4












          4








          4







          You are passing the code ref to the original call to SolveTowerOfHanoiProblem, but not to the recursive calls.



          You could simply pass the code ref.



          SolveTowerOfHanoiProblem($n - 1, ..., $moveDisk);


          Or could remove the need to pass the same value over and over again.



          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          local *helper = sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          helper($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          helper($n - 1, $extra, $end, $start);
          }
          };

          helper(@_);
          }


          Same, but using a feature introduced in Perl 5.16:



          use feature qw( current_sub );

          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          __SUB__->($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          __SUB__->($n - 1, $extra, $end, $start);
          }
          }->(@_);
          }





          share|improve this answer















          You are passing the code ref to the original call to SolveTowerOfHanoiProblem, but not to the recursive calls.



          You could simply pass the code ref.



          SolveTowerOfHanoiProblem($n - 1, ..., $moveDisk);


          Or could remove the need to pass the same value over and over again.



          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          local *helper = sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          helper($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          helper($n - 1, $extra, $end, $start);
          }
          };

          helper(@_);
          }


          Same, but using a feature introduced in Perl 5.16:



          use feature qw( current_sub );

          sub SolveTowerOfHanoiProblem {
          my $moveDisk = pop;

          sub {
          my ($n, $start, $end, $extra) = @_;

          if ($n == 1) {
          $moveDisk->($n, $start, $end);
          } else {
          __SUB__->($n - 1, $start, $extra, $end);
          $moveDisk->($n, $start, $end);
          __SUB__->($n - 1, $extra, $end, $start);
          }
          }->(@_);
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 6:02

























          answered Nov 23 '18 at 5:32









          ikegamiikegami

          262k11176396




          262k11176396













          • Wow, I hadn't come across nested subroutines like this, thanks for the heads up

            – Jose Fernando Lopez Fernandez
            Nov 24 '18 at 4:27






          • 1





            Just don't nest named subs

            – ikegami
            Nov 24 '18 at 4:29



















          • Wow, I hadn't come across nested subroutines like this, thanks for the heads up

            – Jose Fernando Lopez Fernandez
            Nov 24 '18 at 4:27






          • 1





            Just don't nest named subs

            – ikegami
            Nov 24 '18 at 4:29

















          Wow, I hadn't come across nested subroutines like this, thanks for the heads up

          – Jose Fernando Lopez Fernandez
          Nov 24 '18 at 4:27





          Wow, I hadn't come across nested subroutines like this, thanks for the heads up

          – Jose Fernando Lopez Fernandez
          Nov 24 '18 at 4:27




          1




          1





          Just don't nest named subs

          – ikegami
          Nov 24 '18 at 4:29





          Just don't nest named subs

          – ikegami
          Nov 24 '18 at 4:29


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437406%2fperl-passing-function-as-an-argument-undefined-sub-reference%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'