Login

Join for Free!
114700 members
table of contents table of contents

Biology Articles » Bioinformatics » Introductory Workbook on Perl for Biology Students » 9. Perl program to operate array of variables

9. Perl program to operate array of variables
- Introductory Workbook on Perl for Biology Students

The present program demonstrates pop, push, copy and sort operations on arrays. These are very straight forward commands which are very easy to understand. The array @array is filled with 4 values. Using the pop operation we remove the last value of the array. The value is stored in $array. The push operation pushes the value ‘iso’ into the last position of the array. The result of the new array is stored in @RE. The copy operation is done by just passing the values to the new array @array1. The sort operation alphabetically sorts all the values of the array and stores them in @RE.

 

1.    #perform pop, push, copy and sort functions

2.    #original array operations

3.    @array=('ecor1', 'bam', 'hind', 'avi');

4.    print"the original array:@array\n";

5.    #pop operation

6.    $array=pop(@array);

7.    print"the pop results:@array\n";

8.    #push operation

9.    @RE=push(@array,'iso');

10.     print"push function:@array\n";

11.     #copy operations

12.     @array1=@array;

13.     print"the copy results:@array1\n";

14.     #sort operations

15.     @RE=sort(@array);

16.     print"the result of sort:@RE\n";

 

 

RESULTS:

 

the original array:ecor1 bam hind avi

the pop results:ecor1 bam hind

push function:ecor1 bam hind iso

the copy results:ecor1 bam hind iso

the result of sort:bam ecor1 hind iso


rating: 3.71 from 112 votes | updated on: 30 Jan 2009 | views: 91755 |

Rate article:







excellent!bad…