in reply to code reference in YAML
First the YAML file looks like this:
And to use code from a YAML file you must put the UseCode-switch on.--- - - 1 - !!perl/code | { print "one"; }
use Modern::Perl; use YAML qw/LoadFile/; local $YAML::UseCode = 1; my $s = YAML::LoadFile( "code.yml" ); my $f = $s->[ 0 ]->[ 1 ]; $f->();
Beware that using Perl code from a YAML file involves this code to be evaled, with all security risks that come with it. That is the reason why by default the UseCode-switch is 0 (off).
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: code reference in YAML
by Anonymous Monk on Jan 27, 2011 at 17:20 UTC | |
by CountZero (Bishop) on Jan 27, 2011 at 17:24 UTC | |
by roboticus (Chancellor) on Jan 27, 2011 at 18:29 UTC | |
by ikegami (Patriarch) on Jan 27, 2011 at 18:53 UTC | |
by GrandFather (Saint) on Jan 27, 2011 at 23:26 UTC |