dda has asked for the wisdom of the Perl Monks concerning the following question:
Please look at the code example:
What if I want to keep the old contents somewhere? I found that changing the line#!/usr/bin/perl -w use strict; my @a = (1,2,3,4); my $p = \@a; print "before:\n"; foreach (@{$p}) { print "element $_\n"; } @a = (); print "after:\n"; foreach (@{$p}) { print "element $_\n"; }
tomy $p = \@a;
does the trick. Is it a correct way?my $p = [@a];
--dda
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Duplicating array contents
by jdporter (Paladin) on Dec 16, 2002 at 15:10 UTC | |
|
(jeffa) Re: Duplicating array contents
by jeffa (Bishop) on Dec 16, 2002 at 15:12 UTC | |
by Aristotle (Chancellor) on Dec 16, 2002 at 19:29 UTC | |
|
Re: Duplicating array contents
by BrowserUk (Patriarch) on Dec 16, 2002 at 15:12 UTC |