in reply to Re: Preserve the value of original array
in thread Preserve the value of original array

Thanks, Darren :)

I need to copy the array into an array, and not make a copy of the reference, as in:

sub second { my $num_ref = shift; my $copy_of_ref = $num_ref; push(@$copy_of_ref, 6); my $sum = 0; foreach (@$copy_of_ref) { $sum += $_; } return $sum; }
Am I right?

Replies are listed 'Best First'.
Re^3: Preserve the value of original array
by McDarren (Abbot) on Feb 14, 2006 at 06:20 UTC
    Yes, that's fine. But please also take note of bobf's comments below :)

    Update:Actually, I misread what you said there. Either way is okay. You can either take a copy of the reference, or dereference it into another array. But again, as bobf already pointed out in his update - the simplest way is to just pass the array (rather than a reference) - and then take a copy of that.