Hameed has asked for the wisdom of the Perl Monks concerning the following question:
One thing I realized that there is the difference between#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my @array1 = (['A', 'B'], 1, 2, 3, ['One', 'Two', 'Three', ['I', 'II', + 'III'], 'Four'], 4); print Dumper (\@array1); recReverse (\@array1); print "\n===============Reversed================\n"; print Dumper (\@array1); my $count = 0; sub recReverse { my $ref2array = shift; if (ref $ref2array eq 'ARRAY') { my @newarray = reverse (@$ref2array); @$ref2array = @newarray; for my $item (@{$ref2array}) { recReverse($item); } } }
andmy @newarray = reverse (@$ref2array); @$ref2array = @newarray;
I was under the impression that both do the same thing, however I only realized that they don't. Can someone explain the difference. I mean I have seen it in action but not sure I fully understand the concept. Thanks.my @newarray = reverse (@$ref2array); $ref2array = \@newarray;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array Reference Question
by b4swine (Pilgrim) on Sep 09, 2014 at 06:08 UTC | |
|
Re: Array Reference Question
by Laurent_R (Canon) on Sep 09, 2014 at 06:58 UTC | |
|
Re: Array Reference Question
by b4swine (Pilgrim) on Sep 09, 2014 at 06:17 UTC | |
by Hameed (Acolyte) on Sep 09, 2014 at 06:31 UTC | |
by Hameed (Acolyte) on Sep 10, 2014 at 00:40 UTC |