#!/usr/bin/perl # simple example, how perl can work with the output of a space delimited array # and work with it as a matrix. An entry of the matrix can then be accessed # for example m(3,3). Its easy then to make spreadsheet calculations within # perl, without having to use excel-type-tools. In this example, the 3'th row # is added up. # usage examples: # matrix.pl < file.in > file.out @command=; $delimiter=" "; $num_of_rows=$#command+1; $sum=0; for ($k=1; $k<=$num_of_rows; $k++) { $sum+= &m($k,3); } print $sum,"\n"; sub m { my @indices=@_; my $i=@indices[0]-1; my $j=@indices[1]-1; $line=@command[$i]; @entries=split($delimiter,$line); $num_of_columns=$#entries; $entry=@entries[$j]; return $entry; }