[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 ?
Yossi



                                                                                                                                   
                      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                                                                                             
                      l.org.il                                                                                                     
                                                                                                                                   
                                                                                                                                   
                      02/15/2004 14:37                                                                                             
                      Please respond                                                                                               
                      to Perl in                                                                                                   
                      Israel                                                                                                       
                                                                                                                                   
                                                                                                                                   



>
>
>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],
$array[$i2],$array[$i3],...).
By the way, the @hash{$k2,$k2,$k3,...} is an abbreviaiont for the list
($hash{$k1},$hash{$k2},$hash{$k3}).
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.
Yaakov


_______________________________________________
Perl mailing list
Perl at perl.org.il
http://www.perl.org.il/mailman/listinfo/perl

YAPC::Israel::2004
http://www.perl.org.il/YAPC/2004/







More information about the Perl mailing list