[Israel.pm] scalars and arrays

Yossi.Itzkovich at ecitele.com Yossi.Itzkovich at ecitele.com
Sun Feb 15 04:55:11 PST 2004

Is there any performance penalty using the wrong syntax ?

                      Yaakov Belch                                                                                                 
                      <lists at yaakovnet         To:      Perl in Israel <perl at perl.org.il>                                          
                      .com>                    cc:                                                                                 
                      Sent by:                 Subject: Re: [Israel.pm] scalars and arrays                                         
                      perl-bounces at per                                                                                             
                      02/15/2004 14:37                                                                                             
                      Please respond                                                                                               
                      to Perl in                                                                                                   

>I know that: @array[$y]=8; should be written as: $array[$y]=8;
>But  what is really happens when I write it as in the first example ?
@array[$i1,$i2,$i3,...] is an abbreviation for the list ($array[$i1],
By the way, the @hash{$k2,$k2,$k3,...} is an abbreviaiont for the list
This feature is called "array slices" (or, respectively, "hash slices")
and is occasionally very useful.

Thus, @array[$y]=8 means ($array[$y])=(8); because the left hans side is
a list, the
right hand side is evaluated as a list (one element: 8).  In the end,
you get the same result
as $array[$y]=8.

>Why @array isn't modified ?
I tested that on my perl and @array[$y]=8 really changes the list @array.

Perl mailing list
Perl at perl.org.il


More information about the Perl mailing list