You should show us some code.

Normally you would do this in the subroutine:

sub routine {

   my $mydir = shift;
   # which puts the value of $_[0] into $mydir
   # and then removes that from the argument list
   chop $mydir;
   # do stuff with $mydir

}

That makes a copy of the value. It sounds like you are doing this:

sub routine {
   chop $_[0];
   # do stuff with $_[0]
}

which is harder to understand, since $_[0] has no meaning for anyone, and has the disadvantage of changing your original value.

If for some reason you sometimes need to pass the original variable and sometimes pass a copy of the value to your subroutine, you could pass it an expression that returns the value of $a. There's probably a good way I can't think of to do this in all circumstances, but if it's a string you could call it with

routine("$a");

or if it's a number,

routine($a + 0);

By the way, you should look at "chomp" and see if it's more like what you want than "chop". Maybe it is; maybe it isn't.

On Jul 4, 2006, at 10:17 AM, [EMAIL PROTECTED] wrote:

I have a subroutine that, amongst other things, chops a scalar variable, $dir, passed to it as an argument. The problem is that I need $dir intact (ie unchopped) after calling said subroutine, but it has been altered by the chop.

--
Aaron Priven, [EMAIL PROTECTED], http://www.priven.com/aaron


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