in reply to How to replace empty values with value in previous array

#!perl use strict; my @prev = (); my @data = (); while (<DATA>){ chomp; my @row = split ';',$_; for my $i (0..$#row){ if ( length ($row[$i]) == 0 ){ $row[$i] = $prev[$i]; } } push @data,\@row; @prev = @row; } for (@data){ print join "\t",@$_,"\n"; } __DATA__ 1668;1733;60;32;3173;0;2517;58221;55764;0;0;0;0;Td;30720;1;9;25;0;2; C +arry 0; 1671;1661;0;0;;;0;0;0;0;;;;;;1;9;25;0;2; Carry 1;
poj

Replies are listed 'Best First'.
Re^2: How to replace empty values with value in previous array
by Fshah (Initiate) on Jul 20, 2017 at 08:53 UTC

    Thanks for the reply, I have an array with 100's of these lines how can I perform the same operation over entire array line by line

      Do you want to create a new array or overwrite the existing ?

        I want to overwrite the array(considering It might be faster)