Dave's Brain

Browse - Programming Tips - How do I append an element to a perl array?

Date: 2014nov11
Language: perl

Q.  How do I append an element to a perl array?

A.  Use push() like this:

push(@a, 'new element');
Note that push() works in-place. So do NOT do this:
@a = push(@a, 'new element'); # WRONG, WRONG, WRONG

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.