Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Upon execution, I get the following result:#!/usr/bin/perl my @list = (0, 1, 2, 3, 4, 5, 6, 7); print "@list\n"; my @short = @list[1..4]; print "@short\n"; my $ref = \{@list[2..4]}; print "@$ref\n";
...which complains about the reference in the final print statement.0 1 2 3 4 5 6 7 1 2 3 4 Not an ARRAY reference at test.pl line 7.
Of course, I can take the indirect route of copying the array slice into another array of which I can get the reference:
...but I would think that I could do this directly. Any illumination any of you would be appreciated. Thanks.#!/usr/bin/perl my @list = (0, 1, 2, 3, 4, 5, 6, 7); print "@list\n"; my @short = @list[1..4]; print "@short\n"; my $ref = \@short; print "@$ref\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reference to an array slice?
by Enlil (Parson) on Sep 25, 2003 at 21:41 UTC | |
by sauoq (Abbot) on Sep 25, 2003 at 21:53 UTC | |
|
Re: reference to an array slice?
by Abigail-II (Bishop) on Sep 25, 2003 at 21:42 UTC | |
|
Re: reference to an array slice?
by BrowserUk (Patriarch) on Sep 25, 2003 at 22:12 UTC | |
|
Re: reference to an array slice?
by Limbic~Region (Chancellor) on Sep 25, 2003 at 21:41 UTC | |
|
Re: reference to an array slice?
by sauoq (Abbot) on Sep 25, 2003 at 21:49 UTC | |
|
Re: reference to an array slice?
by exussum0 (Vicar) on Sep 26, 2003 at 02:57 UTC | |
|
Re: reference to an array slice?
by broquaint (Abbot) on Sep 26, 2003 at 10:25 UTC | |
by BrowserUk (Patriarch) on Sep 26, 2003 at 11:37 UTC |