Thursday, October 14, 2010

shift, unshift, pop, push, splice

# shift, unshift, pop, push, splice
#use strict;
use warnings;
$\ = "\n";
print "Shift Operator - removes first element from the list/array";
my @testarray = ("alpha", "beta", "gamma");
# print $testarray[0];
# print @testarray;
my $val = shift(@testarray);
print $val;
print @testarray; # returns beta and gamma only
print "\n Unshift Operator - returns total elements.";
my @a = (a,b,c);
my $ret = unshift(@a,1,2,3);
print $ret; # returns numreic value 6.
print "\n POP Operator - removes top most element in the list ie., last element";
my @b = (11,12,13,14);
print pop(@b); # returns item which it is going to remove
print @b;
print "\n Push Operator - appends new element and returns new count NUMERIC.";
my @c = (1);
my $num = push(@c,2,4,6,8);
print $num;
print @c;
print "\n Splice Operator - returns list";
my @list = ("a","b","c","d","e");
my @result = splice(@list,0,3,"+","*","-");
print @result;
print @list;
return 1;

No comments:

Post a Comment

 

©2010 Software Testing powered by Free Blogger Templates | Author : Anand Satish