[ABE.pm] Reference fun
Ricardo SIGNES
perl.abe at rjbs.manxome.org
Fri Nov 9 18:06:55 PST 2007
* "Faber J. Fedor" <faber at linuxnj.com> [2007-11-09T20:35:46]
> However, this code:
>
> use YAML::Tiny;
> use Config::IniFiles;
>
> my $inFile = 'foo.ini' ;
> my %fndVars ;
>
> tie %fndVars, 'Config::IniFiles', ( -file => $inFile);
>
> my $ref = \%fndVars;
>
> my $yaml = YAML::Tiny->new;
> $yaml->[0] = $ref;
> $yaml->write("foo.yml");
>
> produces a file like this:
>
> --- {}
You have a HUGE difference here:
> tie %fndVars, 'Config::IniFiles', ( -file => $inFile);
Once you're using a tied variable, all bets are off. I would be happy to take
a commission to make it work, though. :-)
> If I replace '$yaml->[0] = $ref;' with '$yaml->[0] = %fndVars;' I get
> this:
>
> --- 0
You can't put a hash directly into an array element, only a reference to it.
Otherwise, you're using the hash in scalar context. Normally, that gives you a
fairly useles string describing hash bucket usage, like "3/8." With a tied
hash, all bets are off. Usually you get false.
For .ini files, I use Config::INI (and ::Reader and ::Writer).
--
rjbs
More information about the ABE-pm
mailing list