in reply to Re:yaml dynamically load in perl
in thread yaml dynamically load in perl

Thanks a lot for your inputs. Would check tied hash later.

And could you show my how to call the 'CODE' or 'ref' in Yaml.

For instance, Here is Yaml format: cmd:!perl/ref my_print

Perl Code:
$my_print = sub { print "howdy"; };
How do I make 'cmd' to call $my_print after load the Yaml file into $conf like:
&{ $conf->{"cmd"} }
To make it run and print "howdy".

Replies are listed 'Best First'.
Re^3: yaml dynamically load in perl
by AnomalousMonk (Archbishop) on Nov 02, 2015 at 13:39 UTC

    Not sure if this answers your general question, but here are some specific alternatives:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $my_print = sub { print qq{howdy @_}; }; ;; my $conf = { 'cmd' => $my_print }; ;; &{ $conf->{'cmd'} }; $conf->{'cmd'}->('there'); $conf->{cmd}('doody'); " howdy howdy there howdy doody


    Give a man a fish:  <%-{-{-{-<

      The point is that we need work with Yaml format:
      cmd:!perl/ref my_print
      Not directly with perl anonymous subroutine.