This would be a very silly way to accomplish this, but it works. :)

use strict; use warnings; use Data::Dumper; use Spreadsheet::Engine; my @data = ( [qw( red 15 2 smith )], [qw( blue 4 10 walter )], [qw( blue 4 10 walter )], [qw( red 15 2 smith )], ); my @commands = ( 'set E_ formula IF(B_>C_,B_,"")', 'set F_ formula IF(B_<C_,B_,"")', 'set B_ formula IF(E_,C_,F_)', 'set F_ formula IF(B_<C_,C_,"")', 'set C_ formula IF(E_,E_,F_)', 'set E_ formula IF(F_,"","+")', 'set F_ value v', ); my $sheet = import( @data ); for my $row (0 .. $#data) { $sheet = apply( $sheet, $_, $row + 1 ) for @commands; } print Dumper [ export( $sheet ) ]; sub apply { my ($sheet, $formula, $row) = @_; $formula =~ s/_/$row/g; $sheet->execute( $formula ); $sheet->recalc; import( export( $sheet ) ); } sub import { my @data = @_; my $sheet = Spreadsheet::Engine->new; for my $row (0 .. $#data) { for my $col (0 .. $#{ $data[$row] }) { my $key = Spreadsheet::Engine::Sheet::number_to_col( $col ++ 1 ) . ( $row + 1 ); my $val = $data[$row][$col] || ''; my $type = $val =~ /\D/ ? 'v' : 'n'; $sheet->execute( "set $key value $type $val" ); } } return $sheet; } sub export { my $sheet = shift; my @data = (); for my $row (0 .. $sheet->raw->{sheetattribs}{lastrow} - 1) { my @tmp; for my $col (0 .. $sheet->raw->{sheetattribs}{lastcol} - 1) { my $key = Spreadsheet::Engine::Sheet::number_to_col( $col ++ 1 ) . ( $row + 1 ); push @tmp, $sheet->raw->{datavalues}{$key}; } push @data, [@tmp]; @tmp = (); } return @data; } __DATA__ $VAR1 = [ [ 'red', '2', '15', 'smith', '+', '' ], [ 'blue', '4', '10', 'walter', '', '' ], [ 'blue', '4', '10', 'walter', '', '' ], [ 'red', '2', '15', 'smith', '+', '' ] ];

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: switching two columns under conditions (Spreadsheet::Engine) by jeffa
in thread switching two columns under conditions by gghelpneeded

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.