Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Namespace variable gathering

by dpatrick (Scribe)
on Apr 24, 2002 at 20:23 UTC ( #161770=perlquestion: print w/replies, xml ) Need Help??

dpatrick has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

As here,
my $emailBodyTmpl = new HTML::Template::eyemg( filename => "protected/tpm/comments.tmpl", path => "$LocalLib::docroot" ); $emailBodyTmpl->param( supplierName => $fromQuery::supplierName, supplierNumber => $fromQuery::supplierNumber, reportDate => $fromQuery::reportDate, ); my $body = $emailBodyTmpl->output();

is there are way for me to refer to all of the variables in a particular namespace, similar to doing this
$emailBodyTmpl->param( %{ @arrayOfData[0] }, );
?


dpatrick
- I think scsh is cool.
Open Sourceror, Perlmonk
http://perlmonk.org/~dpatrick

Replies are listed 'Best First'.
Re: Namespace variable gathering
by samtregar (Abbot) on Apr 24, 2002 at 22:16 UTC
    Yes, all packages have a hash for their symbol table. The keys are symbol names and the values are typeglobs. There are many ways to use the symbol table to get a list of names and scalar values. Here's one - it calls $template->param() with the names and values in the package "Values":
    { no strict 'refs'; $template->param(map { $_ => ${"Values::$_"} } keys %Values::); }

    -sam

Re: Namespace variable gathering
by dsb (Chaplain) on Apr 24, 2002 at 21:07 UTC
    I'm not really sure what you mean by namespace:
    A package's namespace?
    All variable types with the same name(i.e. $var,@var,%var)? For this you could do a typeglob.
    *foo = *bar;
    This line sets all of the variable types with the name foo to the values of the corresponding variable types with the name bar

    Or do you mean all of a hash's or array's values? For this you could look into hash and array slices.

    @arr[3,4,5,6] = qw(just another perl hacker); @hash{'key2','key3','key4','key5'} = qw(jay dave guy);
    Note that with the hash slice we are using the symbol normally associated with arrays. That is because this the left operand is list of keys.




    Amel
      I'm pretty sure he mean "all of the defined variables in a given package". I know it's possible, one of the Apache monitoring modules let's you view it, I just haven't bothered to track it down.

      --
      perl -pew "s/\b;([mnst])/'$1/g"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://161770]
Approved by ichimunki
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-03-31 13:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (75 votes). Check out past polls.

    Notices?