954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Stripping the last element off an array

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

bigfoot_80906
Newbie Poster
17 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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...

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Thanx ... Just what I needed.

RBBD
Newbie Poster
1 post since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You