HRitter

Learning anonym subs child parent

Sep 4th, 2023 (edited)
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use 5.010;
  4. use strict;
  5. use warnings;
  6.  
  7. my %sub_func;
  8. %sub_func = (
  9.     parent_dad => sub {
  10.         print "\tcalled: sub parent_dad()\n";
  11.         sub_func{child}->();                                    # <--- How to call another anonym sub from sub?
  12.     },
  13.     parent_mom => sub {
  14.         print "\tcalled: sub parent_mom()\n";
  15.         sub_func{child}->();                                    # <--- How to call another anonym sub from sub?
  16.     },
  17.     child => sub {
  18.         print "\tcalled: sub child()\n";
  19.     }
  20. );
  21.  
  22.  
  23. my @calls = qw(
  24.     parent_dad
  25.     parent_mom
  26. );
  27.  
  28. foreach (@calls) {
  29.     $sub_func{$_}->();
  30. }
Advertisement