Perl Class simple problem
From: Graeme McLaren (iamnotregistered_at_hotmail.com)
Date: 05/29/04
- Previous message: Ricardo Signes: "Re: The >> operator"
- Next in thread: Charles K. Clarkson: "RE: Perl Class simple problem"
- Reply: Charles K. Clarkson: "RE: Perl Class simple problem"
- Reply: Drieux: "Re: Perl Class simple problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Sat, 29 May 2004 13:10:12 +0100
Afternoon all, I'm trying to write a class for configuration values for
different sites so that they can use the same conf class, then create an
object and get whatever value they need.
The problem I have this:
I create an object and pass a value to my constructor like this:
Conf->new(site=>'x'), this tells the constructor which site I want the
config for, then at the end of the constructor I call $self->_init();
This passes a reference to $self ( I think ) using $self = shift; When I
die out using: die %{$self};
I get the value that "x" equals ( x => '/usr/local/apache/htdocs/x' ) I
need to perform additional logic in $self->_init(); and what I really need
to do is get the name, which in this case is "x" instead of the value which
in this case is "/usr/local/apache/htdocs/x". How do I do this I'm a bit
lost with perl OO programming :(
Thank you for any light anyone can shed on this.
Graeme :)
################ Perl Code #################
sub new{
my ($caller, %arg) = @_;
my $conv = {
x => '/usr/local/apache/htdocs/x',
y => '/usr/local/apache/htdocs/y',
z => '/usr/local/apache/htdocs/z'
};
my $caller_is_obj = ref($caller);
my $class = $caller_is_obj || $caller;
my $self = bless {}, $class;
$self->{_doc_root} = $conv->{$arg{site}||'x'};
if(!exists $conv->{$arg{site}}){
die "check for typos in yer params";
}
$self->_init();
}
sub _init{
my $self = shift;
die %{$self};
}
##################### End of Perl Code ####################
_________________________________________________________________
Get a FREE connection, FREE modem and one month's FREE line rental, plus a
US or European flight when you sign up for BT Broadband!
http://www.msn.co.uk/specials/btbroadband
- Previous message: Ricardo Signes: "Re: The >> operator"
- Next in thread: Charles K. Clarkson: "RE: Perl Class simple problem"
- Reply: Charles K. Clarkson: "RE: Perl Class simple problem"
- Reply: Drieux: "Re: Perl Class simple problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|