gobisankar has asked for the wisdom of the Perl Monks concerning the following question:
Dear friends, I am doing a simple exercise using perl array reference. I want to print last element in the array using reference values. code which i written is given below
#!/usr/bin/perl @arr_val=(1,2,3,4,5,6,7,8); $arr_ref=\@arr_val; print $$arr_ref[-1]; print "\n"; print $$arr_ref[@$arr_ref-1]; print "\n"; print $#arr_val; print "\n"; print $#arr_ref;
Actually my doubt here is print $#arr_val is printing 7, at the same time print $#arr_ref is printing -1. What i have to do if i want to get last index i.e 7 using perl reference with the same method like $#arr_val.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print last element using perl reference
by kennethk (Abbot) on Apr 29, 2010 at 15:49 UTC | |
|
Re: Print last element using perl reference
by moritz (Cardinal) on Apr 29, 2010 at 15:42 UTC | |
by gobisankar (Acolyte) on Apr 29, 2010 at 16:54 UTC | |
|
Re: Print last element using perl reference
by ikegami (Patriarch) on Apr 29, 2010 at 15:53 UTC | |
|
Re: Print last element using perl reference
by pemungkah (Priest) on Apr 29, 2010 at 18:44 UTC |