in reply to Maintaining strict refs while Binding a set of variables to @_ or dying if they are not defined

I want to be able to ensure a set of variables will all have values before assigning them to @_

But that's not what you're doing here. You're checking that the values in @_ are defined before assigning them to your local variables using a horribly complex statement.

Do you have to know the variable name? Wouldn't the parameter number be enough to track down any problems? I'd probably wrtie it something like this:

use strict; sub file_name { die "incorrect number of parameters\n" unless @_ == 4; for each (0 .. $#_) { die "invalid parameter [$_]\n" unless defined $_[$_]; $" = ''; "I@_"' }

Oh, and the commas in your qw are probably a bug too.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

  • Comment on Re: Maintaining strict refs while Binding a set of variables to @_ or dying if they are not defined
  • Download Code

Replies are listed 'Best First'.
Re: Re: Maintaining strict refs while Binding a set of variables to @_ or dying if they are not defined
by arturo (Vicar) on Nov 29, 2000 at 20:30 UTC
    Wouldn't the parameter number be enough to track down any problems?

    Well, if instead of passing in a list of constants, he might well be passing in enough arguments, but one of them have a value of undef (which, of course, the second bit of your code would catch).

    Seems to me wanting the name of the invalid variable is one more step in princepawn's "the secretary should be able to use the program" ethic. Whether or not we agree with that aim is another matter =)

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor