Hello !

It's not a trouble report, but I'll share my experience and maybe somebody could tell me if there is
better/simpler solution.

I had to create code, that will alias to shortcut variable.

Simple answer is
*V = \$some_long_var;
So, modifying $V will change $some_long_var also because of aliasing.

*But* this does not work in mod_perl/Mason environment

E.g. real code snippet:

           my %field_vals;
           if ( $Q::process2 )
           {
                   foreach my $hr ( @fields )
                   {       next if $$hr{HIDDEN} eq 'Y';

                           my $name = $$hr{PARAM_NAME};
local/my/our $V; *V = \$field_vals{$name}; #aliasing -- troubles were here
                           $V = eval('$Q::' . $name);
                           #...

                  #...
                  #we need to access modified %field_vars here...

Declaring $V
- as "local" will lead to "Variable "$V" is not imported at..." error.
- as "my" will not publish changes to outer scope
- as "our" works, but potentially is not safe in mod_perl/Mason since you'll change global $V,
  which is maybe used in another subroutines...

So, after reading documentation I found rarely used "local our" variable declaration syntax.
Therefore aliasing should look like
           local our $V;
           *V = \$some_long_var;
in mod_perl/Mason environment.
It solved my problems, and I hope it will help somebody else.


Thanks,
Ruslan




------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to