Is there a command in Perl that will strip off the last element in an array and replace it with a constant value?

Re: Stripping the last element off an array 80 80

Not to replace it so much, but you could just as easily do a pop and then an immediate push. So, something like:

$retval = pop(@arrayname);
push @arrayname, $newvalue;

so, $retval will contain the last item in the array, but the array will be one element less, and will not contain the last value any longer.... but $retval will. Then, you push the newvalue you want onto the array... this will essentially, remove the last element, and replace it with a new value...

Re: Stripping the last element off an array 80 80

Thanx ... Just what I needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.