Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Forum » x-Forum » Question

How to find the horizontal absolute value in perl in a big

Hi. I have this code:

use strict;
use warnings;
use feature 'say';

use Data::Dumper;
my $flag = 1;
my @current;
my @previous;
my @final;

say "First step";

while( <DATA> ) {
    @current = split ' ';
    if( $flag ) {
        @previous = @current;
        $flag = 0;
        next;
    }
    if( $#current != $#previous ) {
    } else {
        my @data = map { abs($current[$_]-$previous[$_]) } 0..$#current;
       # say join ' ', @data;
        push @final, \@data;
    }
    @previous = @current;
}

say "Second step";
foreach my $row (@final) {
    my @data = map { abs(@{$row}[$_]-@{$row}[$_+1]) } 0..$#{$row}-1;
    say join ' ', @data;
}


which is resulting the absolute value of row2 -row1 (first step). After that the absolute value of row2 -row1 (horizontal absolute value)(Step2). My goal to keep going to obtain the abs(row2 -row1) hozontical in big file containing on big aray n*x so as to have one single columm at the end as following. 

First stage
0 2 0 0
0 1 1 1
Second stage
2 2 0
1 0 0
third stage
0 2
1 0
forth stage
2 
1
----------
Does anyone have any idea how to handle with? 
Thanks in advance. 

Posted by G.Papa 2020-01-28 14:46:51

No Ans Posted

Please login to comment

Log In


Ask New Question