in reply to How to substitute the elements in an array without changing the original array.
I have a box of a dozen doughnuts. I want to eat three of them, and still have a full box with a dozen when I'm done.
Solution? You need another box. ;)
In Perl, you need two arrays; one is the original, and one will be the copy, on which you can perform whatever manipulations you wish, without affecting the original.
my @array = qw/one two three four five/; my @copy = @array; shift @copy; print "Original: @array\n"; print "Copy: @copy\n";
There are infinite other strategies, but your question is vague enough to make it impossible to focus on which strategy would be optimal.
Dave
|
|---|