in reply to •Re: Re: Re: simple tie?
in thread simple tie?

Error: Variable "%userdata" is not imported at library.pl line 242. Here is the code:
sub some_sub { require 'wpconfig.cgi'; tie(%config, 'tie::config'); tie(%userdata, 'tie::config'); } package tie::config; @ISA = qw(Tie::StdHash); use strict; sub STORE { my $self = shift; $self->SUPER::STORE(@_); saveConfig(); } # saveConfig: This is what actually saves wpconfig.cgi. sub saveConfig { my $fh = main::open '>wpconfig.cgi'; print $fh "# DO NOT MODIFY THIS FILE\n# IT IS GENERATED DYNAMICALL +Y!!\n\n"; print {$fh} main::genHash(config); # genHash just takes the hash a +nd generated perl code for it. print {$fh} main::genHash(userdata); print $fh "\n1;"; close $fh; } package main; # exit: Exits and unties %config and %userdata. sub exit { untie(%config) if %config; untie(%userdata) if %userdata; # <- line 242 CORE::exit(); }
This works fine (not errors) but it won't update the file.
sub some_sub { require 'wpconfig.cgi'; tie(%config, 'tie::config'); tie(%userdata, 'tie::config'); } package tie::config; sub TIEHASH {} sub STORE { my $self = shift; $self->SUPER::STORE(@_); saveConfig(); } # saveConfig: This is what actually saves wpconfig.cgi. sub saveConfig { my $fh = main::open '>wpconfig.cgi'; print $fh "# DO NOT MODIFY THIS FILE\n# IT IS GENERATED DYNAMICALL +Y!!\n\n"; print {$fh} main::genHash(config); print {$fh} main::genHash(userdata); print $fh "\n1;"; close $fh; } package main; # exit: Exits and unties %config and %userdata. sub exit { untie(%config) if %config; untie(%userdata) if %userdata; CORE::exit(); }

Replies are listed 'Best First'.
Re: Re: •Re: Re: Re: simple tie?
by demerphq (Chancellor) on May 27, 2002 at 17:20 UTC
    Look, a couple of things here.

    Why have you stuck a package in the middle of another? Thats a recipe for madness. Also as merlyn stated using 'tie::config' is going to get you burned. It should be Tie::Config or something (i think that name is taken (it is: Tie::Config and a bunch more as well)).

    Second if you want this problem solved why dont you just download Config::Inifile. Even if you are on a unix platform it does eactly what you are looking for.

    If you want to have two packages in the same file then at least save yourself the headache and put them in contiguous blocks.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.