in reply to Re: code reference in YAML
in thread code reference in YAML

Thank you CountZero! I would have never known !!perl/code... Your example worked perfectly with my Strawberry Perl, except for this warning message. I think it is from *use warnings* in Modern::Perl. We can live with that. :) Thanks again!
perl t.pl Name "YAML::UseCode" used only once: possible typo at t.pl line 4. one

Replies are listed 'Best First'.
Re^3: code reference in YAML
by CountZero (Bishop) on Jan 27, 2011 at 17:24 UTC
    Actually, in order to find out how to write the YAML file I reverse engineered the YAML file.

    I made the data-structure you wanted to have and then dumped it into a YAML file. Easy as pie!

    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

Re^3: code reference in YAML
by roboticus (Chancellor) on Jan 27, 2011 at 18:29 UTC

    Update: Both solutions below are better. I didn't think of how ugly "local ... if ...;" was.


    If you want to make the warning go away without disabling warnings, you could reference the variable twice, like so:

    local $YAML::UseCode = 1 if ! defined $YAML::UseCode;

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      I cringe at "local ... if ...;". It looks too much like illegal "my ... if ...;" for my taste. Alternative:

      $YAML::UseCode if 0; # Silence spurious warning. local $YAML::UseCode = 1;

      I filed a bug report.

      I like:

      local $YAML::UseCode; $YAML::UseCode = 1;

      better.

      True laziness is hard work