Creating a new class that inherits from Config::IniFiles, I encountered a problem using "my" vs. "our". This new class differs from Config::IniFile in that it creates a INI file if one doesn't exist and sets default values. The other difference is that the INI file is rewritten when the script terminates. Here is what I have:

prefs.pm
package prefs; use strict; use Config::IniFiles; our @ISA = qw( Config::IniFiles ); sub new { my $self = shift; my $class = (ref $self) || $self; my $fname = 'fubar.ini'; my $obj; if (-f $fname) { $obj = $self->SUPER::new( -file => $fname ); } else { $obj = $self->SUPER::new(); $obj->SetFileName( $fname ); $obj->AddSection( 'fubar1' ); $obj->newval('var1=default'); } return bless($obj, $class); } sub DESTROY { my $self = shift; $self->RewriteConfig(); $self->SUPER::DESTROY(@_); } 1;
t1.pl
#!/usr/bin/perl -I. use strict; use prefs; my $inifile = new prefs;
t2.pl
#!/usr/bin/perl -I. use strict; use prefs; our $inifile = new prefs;
t1.pl works. t2.pl fails with a file called "fubar.ini-new". The only difference between the two is the creation of $inifile. One uses "my" and the other users "our". Any suggestions? Thanks, Randal

In reply to my VS. our by lathropr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.