You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by FR...@apsys.com.ar on 2002/03/14 19:46:01 UTC

problems returning a hash of hashes using mod_perl

I got a problem

im using mod_perl with a module which stores all the configurations, and
embperl for displaying the wepages

a sub in this .pm has to return a hash with the configurations

but that hash is inside another general hash called configurations, this is
because each user of the program has its own configurations

the sentence im using to return the value is this


code:
--------------------------------------------------------------------------------
|      return %Actions::Vars::config{$conf};                 |
-----------------------------------------------------------------------------------------


being Actions::Vars:: the name of the package, config the general hash and
$conf the name of the subhash

remember that i need the entire subhash.. not values from it

this isn´t working, and because im not very expreinced with perl i searched
across with all the documentations i could find and never an example of
something like this

if you could help i´ll greatly apreciate it



Esta comunicación es exclusivamente para fines informativos. Está dirigida
al destinatario y puede contener información confidencial de Apsys SRL. No
constituye una oferta o solicitud de compra o venta de ningún servicio o
producto, o como la confirmación oficial de ninguna transacción. Cualquier
comentario o afirmación vertida en esta comunicación, no reflejan
necesariamente la posición de Apsys SRL. Si lo recibió por error, por favor
bórrelo y avise de inmediato al emisor.



Re: problems returning a hash of hashes using mod_perl

Posted by Garth Winter Webb <ga...@perijove.com>.
On Thu, 2002-03-14 at 10:46, FRacca@apsys.com.ar wrote:

> code:
> --------------------------------------------------------------------------------
> |      return %Actions::Vars::config{$conf};                 |
> -----------------------------------------------------------------------------------------

You are not access the hash with the proper syntax:

    %Actions::Vars::config

refers to the entire config hash, while:

    $Actions::Vars::config{$conf}

will return you a value from that hash.  Notice the leading '%' has been
replaced with a '$'.  Read the 'perldsc' man page:

    man perldsc

G


Re: [OT]Re: problems returning a hash of hashes using mod_perl

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 19:53 14.03.2002 +0100, Per Einar Ellefsen wrote:
>Again, see perllol, it'll give you insight into this matter.


Oops, like Garth pointed out, this is supposed to be perldsc, and not 
perllol (which gives a description of arrays of arrays, which work in a 
similar way).

>--

Per Einar Ellefsen
per.einar@skynet.be


Re: problems returning a hash of hashes using mod_perl

Posted by Ernest Lergon <er...@virtualitas.net>.
FRacca@apsys.com.ar wrote:
> 
> [snip]
>
> --------------------------------------------------------------------------------
> |      return %Actions::Vars::config{$conf};                 |
> -----------------------------------------------------------------------------------------
> 
Must read:

	return $Actions::Vars::config{$conf};       # returns a hash reference
or
	return % { $Actions::Vars::config{$conf} || {} }; # returns plain hash

and should have been created like this:

my %user_conf = ( foo => 1, bar => 'on' );

$Actions::Vars::config{'user'} = { %user_conf };

One more tip: always say:

use strict;
use warnings;

That should have told you, whats wrong ;-))

See also

http://www.perldoc.com/perl5.6/pod/perldsc.html#Declaration-of-a-HASH-OF-HASHES

Ernest



-- 

*********************************************************************
* VIRTUALITAS Inc.               *                                  *
*                                *                                  *
* European Consultant Office     *      http://www.virtualitas.net  *
* Internationales Handelszentrum *   contact:Ernest Lergon          *
* Friedrichstraße 95             *    mailto:Ernest@virtualitas.net *
* 10117 Berlin / Germany         *       ums:+49180528132130266     *
*********************************************************************


[OT]Re: problems returning a hash of hashes using mod_perl

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 15:46 14.03.2002 -0300, FRacca@apsys.com.ar wrote:
>im using mod_perl with a module which stores all the configurations, and
>embperl for displaying the wepages
>
>a sub in this .pm has to return a hash with the configurations
>
>but that hash is inside another general hash called configurations, this is
>because each user of the program has its own configurations
>
>the sentence im using to return the value is this
>
>
>code:
>--------------------------------------------------------------------------------
>|      return %Actions::Vars::config{$conf};                 |
>-----------------------------------------------------------------------------------------
>
>
>being Actions::Vars:: the name of the package, config the general hash and
>$conf the name of the subhash
>
>remember that i need the entire subhash.. not values from it
>
>this isn´t working, and because im not very expreinced with perl i searched
>across with all the documentations i could find and never an example of
>something like this
>
>if you could help i´ll greatly apreciate it


Hi,

You should read the perllol documentation. It has got lots of information 
about what you're talking about. This isn't a mod_per specific issue.

First of all:
the subhash you are referring to is just a value of the 
%Action::Vars::config has. So you retrieve it like this:
$hashref = $Actions::Vars::config{$conf}

Now, that gives you a hash reference, from which you can access values 
using $hashref->{key} ou $$hashref{key}.
If you want to retrieve the hash in normal form, like this:

my %conf = get_conf($conf);

You need to access all the values of the sub-hash.
So you get:
return %{$Actions::Vars::config{$conf}};
and then you can do:
my %hash = get_conf($conf);   (or whatever)
This is actualle equivalent to:
my $hashref = $Actions::Vars::config{$conf};
my %hash = %$hashref;

Again, see perllol, it'll give you insight into this matter.



-- 
Per Einar Ellefsen
per.einar@skynet.be