From: "Oleg V. Volkov" <[EMAIL PROTECTED]>
> "Dr.Ruud" <[EMAIL PROTECTED]> wrote:
> > Provide code, so we can guess better.
> 
> Here's example how I use it in functions:
> 
> sub add_service{
>  our($login, $type_id, $account_id, $ap_id, $rule);

Please DON'T!

You DO want to use

        my ($login, $type_id, $account_id, $ap_id, $rule);

here, not our()! You do not want to access the GLOBAL variables 
$main::login, $main::type_id, ..., you want to create your own 
variables that belong just to this subroutine and nothing else. It 
doesn't matter that you might have to specify something twice, but 
using our() this way is simple dangerous. Don't.

Please read: http://perl.plover.com/FAQs/Namespaces.html

>  # Here we do some universal sanity checks for all add_* functions
>  attr({ croak_wrong_args(@_) }); print "Adding service type
>  $type_id...\n"; # Here we do actual work # ...
> }
> 
> In this function I also would like to add croaking on passing
> hash with keys that do not used in this function, but in this
> solution this would require manually adding list of used/allowed
> keys to call to sanitizing function, copying "our" declaration.
> 
> That's why I need to either find some way to stack "our" and
> "croak_wrong_args" together, way to give "our" variable names
> from list, so I can pass same list to "our" and to sanitizer
> or to declare our variables one stack frame higher (which I
> think is even less possible than first two).

Maybe there are already modules that will do what you want and more. 
And safer. Have a look at 

Go to http://search.cpan.org/ and see
Params::Named, Sub::Parameters, Sub::Signatures, Params::Smart, 
Perl6::Parameters, Sub::Parameters, ... 

Maybe one of those will help you get where you are trying to go.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
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