David Buddrige wrote:
> 
> Hi all,

Hello,

> I am reading through a collegue's perl script.  In it he has the
> following lines:
> 
> sub SomeSubName
> {
>         my ($vara, $varb, $varc, @items) = @_;
>         my ($itemtype, %symbol);
>         ...
> }
> 
> The first line I understand; here you are getting the parameters to the
> subroutine (which are stored in @_), and putting them into particular
> variable names - $vara, $varb, and so on.
> 
> The second line however, I am not clear what it is doing.
> 
> It seems to be creating an in-line list, but firstly, that list is not
> assigned to anything, and secondly he is storing a hash into the list
> (presumably it must be a reference to a hash, since you cannot actually
> store a hash into a data structure such as a list or an array without
> using refernces...
> 
> Could anyone see what possible value could be had in creating the list:
> 
>         my ($itemtype, %symbol);
> 
> Is this assigned to some default name?


perldoc -f my

       my EXPR

       my EXPR : ATTRIBUTES
               A `my' declares the listed variables to be local
               (lexically) to the enclosing block, file, or
               `eval'.  If more than one value is listed, the
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               list must be placed in parentheses.  See the
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               Private Variables via my() entry in the perlsub
               manpage for details.



That code could also be written as:

sub SomeSubName
{
    my ($vara, $varb, $varc, @items, $itemtype, %symbol) = @_;


:-)

John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to