my ($option) = $_ =~ s/(.*?)#/; #skip inline comments
should be m//, not s// On 6/8/06, Anthony Ettinger <[EMAIL PROTECTED]> wrote:
On 6/8/06, Graeme McLaren <[EMAIL PROTECTED]> wrote: > Hi Anthony, good idea about overriding the table names. I had a feeling > there would be a conf file somewhere. As I am outputting the results of the > SELECT to an HTML::Template I am already using a Conf file which is another > class. This leads me on to another question. If I instantiate my class and > create a Conf object within $log->view then the Conf file won't be loaded > till this method is invoked. I want to have all the Conf details available > at the same time, I don't want to instantiate the Conf class several times > and hold several copies of the Conf in memory when only one is required. So > how or where should I instantiate it? > If everything related to the app is encapsulated withing your Log package, put it in the constructor package Log; sub new { //create object $self->init(); } sub init { open(CONF, $conf) or die "can't open config file: $!"; while(<CONF>) { next if (m/^#/); #skip comments my ($option) = $_ =~ s/(.*?)#/; #skip inline comments my ($key, $val) = split(/\s*=\s*/, $option); $self->{$key} = $val; } close(CONF); return $self; } sub getTablePrefix { my $self = shift; return $self->{'table_prefix'}; } So now when you can print Dumper($self->{'table_prefix'}); and it should have the value from the config file. my $log = new Log; print $log->getTablePrefix(); -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html
-- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>