Hi Graeme

Based on the code snippets you provide, it's not clear (at least to me) what 
you want to achieve.  Is it possible that you post the module?

Am Dienstag, 10. Mai 2005 13.34 schrieb Graeme McLaren:
> John, here's the function I'm talking about.  

an object method?

> I want to return a hash but 
> I'm wondering if I should be assigning it to $self so I am returning an
> object instead of a data structure.  

If the hash is assigned to $self or not does not matter, it is in both case a 
non object data structure.

And designing the content of %conf below as an object with a method 
get_users_table_and_columns() returning all object attributes makes, I think, 
not much sense.

> I hope this is clear to you and thank you for your help.
>
> ####################################################
> sub get_users_table_and_columns{
>   my $self=shift;

This seems to be an object method, $self being the object. 
Do you have a new() class method in your module?

>   my %conf=(
>             table=>'blog',
>             column1 =>'first_name',
>             column2 => 'last_name',
>             column3 => 'email',
>             column4 => 'password',
>             column5 => 'active'
>       );

Since this %conf has fixed content, you could set all that during object 
creation ( new() ) and store it as object attribute, like 
 
 $self->{conf}={table=>'blog',...};

>   return %conf;

...and the method (hopefully not the only one in the class) would get shorter:

 sub get_users_table_and_columns{
  return $_[0]->{conf};
 }

It returns a hashref instead of a hash.


joe


> }
> ####################################################
>
>
> Cheers,
>
> G :)
>
> >From: John Doe <[EMAIL PROTECTED]>
> >To: beginners@perl.org
> >Subject: Re: returning a hash from a method call ?
> >Date: Tue, 10 May 2005 06:50:54 +0200
[...]
> >References: <[EMAIL PROTECTED]>
> >Return-Path: [EMAIL PROTECTED]
> >X-OriginalArrivalTime: 10 May 2005 04:50:23.0825 (UTC)
> >FILETIME=[C6D4F410:01C5551B]
> >
> >Am Montag, 9. Mai 2005 21.56 schrieb Graeme McLaren:
> > > Hi all, I want to return a hash when calling
> > > $conf->get_users_table_and_columns;
> >
> >Below you say that you don't want to return an ordinary hash...
> >
> > > but when I do:
> > > die Dumper($conf->get_users_table_and_columns);
> > >
> > > I get:
> > >
> > > Software error:
> > > $VAR1 = 'column3';
> > >
> > >
> > > What I really want to see is:
> > >
> > > $VAR1 = {
> > > column3 => 'bla1',
> > > key2 => 'bla2'
> > > }
> > >
> > >
> > > I don't want to simply return a reference to a hash because I am
> > > calling
> >
> >a
> >
> > > method on a class and want to keep it object oriented.
> >
> >Even if a method returns a hash, it's object oriented.
> >Do you mean you want to return an object based on a hash???
> >
> > > Anyone know how I would do this?
> >
> >Could you provide some code please?
> >
> >joe


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to