Perl Topics





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Perl Tutorial
Introduction Introduction
Installing Perl Installing Perl
Basics of Perl Basics of Perl
Scalar Variables Scalar Variables
Operators Operators
Control Structures Control Structures
Lists Lists
Array Array
Arrays Manipulation Arrays Manipulation
Arrays Functons Array Functions
Hash Hash
Hash Functions Hash Functions
String Functions String Functions
Regular Expression Regular Expression
Regular Expression Functions Regular Expression Functions
Numerical Functions Numerical Functions
List Functions List Functions
User Defined Function User Defined Function
File Handling File Handling
Forums Ask Your Doubts
Feedback Feedback
 






outsourced web hosting support

Arrays Manipulation in Perl


Tutorials Perl

Topic

How to Manipulate Arrays in Perl?



Explanation

Manipulate or Combine elements to an array in different ways.

     @CombinedArray = (@Array1, @Array2);

Using the above code, the resulting array contains all the elements in @Array1, followed by that of @Array2. To append a scalar element to the end of an array, you can write, for example,

    @MyArray = (@MyArray, $NewElement);
Example to Manipulate Arrays:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    @array1 = ("red", "green");
    @array2 = ("blue", "white");
    @combined = (@array1, @array2);
    $, = "\n";
    print @combined;
    print "<br>";
    @new = (@combined,orange);
    $, = "\n";
    print @new;
Result:
    red green blue white
    red green blue white orange

In the above manipulation example, first two arrays "array1","array2" are combined, then a new element "orange" is added to the existing array as it is a scalar element.








A Note
Simple introduction, basic CGI perl programming codes with examples. Do send your feedback or suggestions on this tutorial. This is a copyright content.

Other Links

web hosting