Well, if you wanted to admit modules, you could have some fun with the PDL module:

#!/usr/bin/perl -w use strict; use PDL; my $v1 = pdl reverse 1..10; my $v2 = pdl 0..9; my $v3 = pdl ((2)x10); my $add = $v1 + $v2; my $mult = $v1 * $add; my $div = $mult / $v3; my $sub = $div - $v1; print "add: $add\nmult: $mult\ndiv: $div\nsub: $sub\n"; # we didn't stomp the original vectors either... # and of course, we can work with matrices too my $matA = pdl [0,0,0],[1,1,1],[2,2,2]; # 2d 3x3 $matA++; # add one across the board $matA *= 2; # and scale up by factor of 2 print "A: $matA\n"; $matA *= $matA; # scale it by itself print "B: $matA\n"; $matA x= $matA; # matrix multiply print "C: $matA\n"; # and say, did you ever want to know the eigenvalues and # eigenvectors of a 4 x 4 matrix of a fibonacci sequence??? use PDL::Slatec; # Fortran never dies :-) my $fibo = fibonacci(4,4); my($eigvals, $eigvecs) = eigsys($fibo); print <<EOF; Fibo matrix: $fibo Eigenvalues: $eigvals Eigenvectors:$eigvecs EOF __END__ add: [10 10 10 10 10 10 10 10 10 10] mult: [100 90 80 70 60 50 40 30 20 10] div: [50 45 40 35 30 25 20 15 10 5] sub: [40 36 32 28 24 20 16 12 8 4] A: [ [2 2 2] [4 4 4] [6 6 6] ] B: [ [ 4 4 4] [16 16 16] [36 36 36] ] C: [ [ 224 224 224] [ 896 896 896] [2016 2016 2016] ] Fibo matrix: [ [ 1 1 2 3] [ 5 8 13 21] [ 34 55 89 144] [233 377 610 987] ] Eigenvalues: [0.859383 6.05138 68.0353 1010.05] Eigenvectors: [ [ 0.99101 -0.13375 -0.00326739 0.00031052] [ -0.131501 -0.97827 0.160279 -0.00218367] [ -0.0244236 -0.156787 -0.974861 0.156421] [ 0.0032657 0.0227098 0.154745 0.987688] ]

In reply to Re: array add/sub/mult/div by danger
in thread array add/sub/mult/div by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.