From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of ukhas
jean
Sent: 11 October 2006 07:49
To: Active Perl
Subject: Query with array references

> Was playing with references and came across a feature of Perl which
puzzles me ... (I was purposefully not 
> using the arrow -> notation to make sure I am well versed with the
other format too ... that's when I spotted 
> the below prob.)
>  
> use strict;
> use warnings;
> 
> my @arr = (10,20,30);
> my $rarray = [EMAIL PROTECTED];
> print "\n====$$rarray[1]=======\n";
>  
> O/p:-
> ====20=======
>  
> This is just fine ... 
>  
> For fun i typed the below line ... and Eureka!!! It gives me the same
output ...
> print "[EMAIL PROTECTED]";
>  
> Q. Is @$rarray[1] a proper way to access an element ...

No it isn't the proper way to access an element (it isn't exactly
improper either, but it probably isn't doing what you might think).
$rarray->[1], or possibly ${$rarray}[1], would have been better. What
you have in the second print statement is the same as if you had written
@arr[1] (which actually generates a warning, if you try it - pity your
code doesn't generate that warning too), i.e. an array slice containing
a single value. As an additional experiment, try replacing [1] with
[1,2] in your two print statements, and notice the difference in their
output.

> The book I read never mentioned this ... or is it 
> something that only I am unaware of ??

Perhaps you missed it. See 'perldoc perldata' for some info on array
slices, also the FAQ 'perldoc -q "@array"'.

HTH

-- 
Brian Raven 



=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message do not 
necessarily reflect those of Atos Euronext Market Solutions.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail 
vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre 
systeme. Le contenu de ce message electronique ne represente pas necessairement 
la position ou le point de vue d'Atos Euronext Market Solutions.

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to