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

Learn'ed Ones,
I have a snippet in which I am using both strict and subroutines, which is admittedly an effort to make perl less true to its nature, but I will hazard the following Q anyway. In this subroutine I want to send and arguement and do some work, without strict I would normally operate as follows ...
&do_work($cmd); sub do_work { local($cmd) = @_; `$cmd`; }

But if I declare strict I cannot get my variable into the routine via the local() statement, which is a scoping issue no doubt. Nevertheless, I cannot seem to resolve this issue via conventional means. Anybody know how to to pass args using strict?

Replies are listed 'Best First'.
Re: Strict and Subroutines
by vek (Prior) on Jul 30, 2002 at 16:16 UTC
    This is probably what you're looking for:
    do_work ($cmd); sub do_work { my $command = shift; # do stuff here... }
    If you need to pass more than one argument, try this:
    do_work ($cmd, $foo); sub do_work { my ($command, $foo) = @_; # do stuff }
    HTH

    -- vek --
Re: Strict and Subroutines
by DamnDirtyApe (Curate) on Jul 30, 2002 at 16:17 UTC
Re: Strict and Subroutines
by VSarkiss (Monsignor) on Jul 30, 2002 at 16:19 UTC

    Begin by reading perlsub.

    The use of local for routine parameter passing is not a good idea; you should be using my instead:

    sub do_work { my ($cmd) = @_; # whatever... }
    While there are circumstances where local is needed, this is not one of them. There are other excellent writeups on this topic in the Tutorials section.

      That was pretty simple. Thanks any sorry for the bother.