Site menu:

Back to examples

Perl Example - Append column to a matrix

#################################################
#Version 0.1                                    #
#Free to use for any purpose                    #
#No credits or backlink required                #
#Author : Shaji Kalidasan (shajiindia@yahoo.com)#
#################################################
use strict;
use warnings;

my @matrix = ( [ qw/tendulkar dhoni raina/ ], [ qw/sangakara muralidharan silva/ ], [ qw/botham peterson williams/ ], );

#append West Indies Team as first column
my @column = qw/walsh ambrose lara/;

for ( my $i = 0 ; $i <= $#matrix ; $i++ ) {
	push @{ $matrix[$i] }, $column[$i];
}

#print the matrix
print map { join '|', @$_, "\n" } @matrix;