--As off Saturday, December 20, 2003 1:57 PM +1100, Colin Johnstone is alleged to have said:

Gidday all,

I want to pass a boolean value as a parameter to a subroutine what
should  I use shift or @_

and whats the difference please.

e.g

mySubRoutine(0);

sub mySubRoutine{
        my $booleanParameter = @_;

        return;
}

--As for the rest, it is mine.



All parameters to subroutines are found in the @_ array for that subroutine. You can assign from that array using shift or directly. The above looks like it is trying to assign from it directly, but it fails slightly. I think you ment this:
my $booleanParameter = $_[0];
(Though I could be wrong. If you are checking whether a parameter was passed at all (or how many) the above could work. Personally I'd prefer not to do that, except as a check to make sure the function was called correctly.)


The difference with using shift or assigning it directly is shift removes the value from the array, assigning it directly does not. This may not make much difference, but occasionally it does.

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

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