How to add value in the beginning of an array in perl – How to add value in the end of an array in perl

Let’ s say the given array is @array, which is initialized as follows:

Adding value in the beginning of an array
Now, let’s say we want to add “abc” to the beginning of the array. This can be done using unshift function provided by perl. Here is the code snippet to achieve the same:

Output would be:
abc def ghi jkl

Adding value in the end of an array
Push function provided by perl, however, adds the value to the end of the array. Let’s say we want to add “mno” to the end of the array. Here is the code snippet in perl to achieve the same:

Output would be:
def ghi jkl mno

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">