Thursday, November 3, 2011

Unshift/Shift

Unshift/Shift :
===========

If you want to simply add or delete an element from the left side of an array (element zero),
you can use the unshift and shift functions.

Unshift (To add a element in element zero) :
===========================


#!/usr/bin/perl
@test = ("test2","test3");
unshift(@test,"test1-added");
print "Added new element using unshift\n @test\n";


$ ./unshift.pl
Added new element using unshift
 test1-added test2 test3
$

Shift (To delete the zero element in an array):
=============================

#!/usr/bin/perl

@sriram = ("one","two","three","four");
shift(@sriram);

print "New Value is \n @sriram\n";

No comments:

Post a Comment