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

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.

Replies are listed 'Best First'.
Re^4: code reference in YAML
by ikegami (Patriarch) on Jan 27, 2011 at 18:53 UTC

    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.

Re^4: code reference in YAML
by GrandFather (Saint) on Jan 27, 2011 at 23:26 UTC

    I like:

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

    better.

    True laziness is hard work