Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  Perl Tutorials
Perl Introduction
Variables
Operators
Character Meanings
Control and Loops
Functions
Array Functions
String Functions
Math Functions
Reading and Writing
Using Cookies
Printing a file
Hit Counter
Poll Receiving
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

Perl Array Functions

Shows some Perl array functions and examples of how to use them.

Delete

%group = ('forest', 'tree', 'crowd', 'person');
delete($group{'forest'})

if (exists($group{'forest'}))
{
	print "The named element was not deleted.\n";
}
else
{
	print "The element was deleted.\n";
}

each

%group = ('forest', 'tree', 'crowd', 'person', 'fleet', 'ship');

while (($key, $value) = each(%group))
{
	print "A $value is part of a $key.\n";
}

Results printed are:

A tree is part of a forest. 
A person is part of a crowd.
A ship is part of a fleet.

exists

%group = ('forest', 'tree', 'crowd', 'person');
if (exists($group{'crowd'}))
{
	print "The named element exists.\n";
}
else
{
	print "No element with that name found.\n";
}

grep

join

The elements in an array are joined into a single string with each element seperated by the value in EXPR.

join EXPR, ARRAY

Example:

@plantlist= (flower, tree, grass);
join " ", @plantlist;

This evaluates to "flower tree grass".

keys

Returns hash keys where:

%group = ('forest', 'tree', 'crowd', 'person');
foreach $key (keys %group) 
{
   print $key . "\n";
}

map

pop

push

reverse

scalar

shift

sort

splice

split

unshift

values

 

<< Previous | Next >>

Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com