Dave's Brain

Browse - Programming Tips - How do I prepend/append in perl?

Date: 2011aug29
Language: perl

Q.  How do I prepend/append in perl?
(Add at the start of an array, add at the end of an array.)

A. Prepend with unshift() - eg:

my(@a); unshift(@a, 'three'); unshift(@a, 'two'); unshift(@a, 'one');
is the same as @a = qw(one two three) A. Append with push() - eg:
my(@a); push(@a, 'one'); push(@a, 'two'); push(@a, 'three');
is the same as @a = qw(one two three)

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.