[ale] OO Perl

Christopher Fowler cfowler at outpostsentinel.com
Thu Apr 15 12:31:22 EDT 2004


I'm creating a Properties class to use with config files for my cgi
programs

package Properties;
use strict;

sub new {
        shift;
        my ($fname) = @_;
        my $options = {};
        my $p = {
                'file' => $fname,
                'options' =  $options
        };
        bless $p;
        return $p;
}



Here is the code I plan on using to parse name,value pairs out of a
file:

my $config = "/etc/perl-passwd.conf";     # Or whatever
my $options = {};                        # Not a hash, a reference to a
hash
open CONFIG, $config or die "Cannot open $config: $!";
while (<CONFIG>) {
        next if /^(#.*)?$/;              # skip comments, blanks
        if (/^\s*(\w+)\s*=\s*(.+)\s*/) {  # Match "blah = foo bar"
                #$options->{$1} = $2      # Set out reference to hash
        } else {
               warn "Error: $_";         # Complain otherwise...
        }
}
close CONFIG;                            # Move along, nothing to see
here...

How can I store $options in a Properties object?  







More information about the Ale mailing list