Ppeoc has asked for the wisdom of the Perl Monks concerning the following question:
I know need to access only certain elements of each row and column. I am running out of memory during this action. Please help me out with thiswhile (my $line = < $in_ph > ) { chomp $line; my@ fields = split(/,/, $line);@ key = split(/_/, $fields[0]); $data[$count][0] = $fields[1]; foreach(@key) { $data[$count][$k + 1] = $key[$k]; $k++; } $k = 0; $count++; }
I need parse data from row 2033 onwards. I have initialised my color, order, shape and name to certain values from my @data. I know have a for loop that traverses from row 3022 to the end of @data. After every 6267 rows traversed, I want to change the value of color, order, shape and name. I am using the if loop for the same. At the same time, I want color, order, shape and name joined with data from column 4 onwards for each row. I keep getting the warning use of uninitialized value in join for the below linemy $n = 2033; my $color = $data[$n][0]; my $order = $data[$n + 1][0]; my $shape = $data[$n + 3][0]; my $name = $data[$n + 4][0]; foreach my $aref(@data[2033..$#data]) { if (($aref - $n) % 6267 == 0) { $color = $data[$aref][0]; $order = $data[$aref + 1][0]; $shape = $data[$aref + 3][0]; $name = $data[$aref + 4][0]; } print $out_ph1 $predata, ",", $color, ",", $order, ",", $shape, ", +", $name, ","; foreach(@{ $aref }[4..$#$aref]) { print $out_ph1 $_, "\_"; } print $out_ph1 "\n"; }
I am also running out of memory before the loop completes. Please help me! I am not sure if the way I have parsed the CSV file is causing this or if the way I am displaying this is.print $out_ph1 $predata, ",", $color, ",", $order, ",", $shape, ",", $ +name, ",";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Running out of memory while running this for loop
by BillKSmith (Monsignor) on Nov 01, 2015 at 18:18 UTC | |
|
Re: Running out of memory while running this for loop
by shmem (Chancellor) on Nov 01, 2015 at 17:06 UTC | |
by Ppeoc (Beadle) on Nov 01, 2015 at 21:57 UTC | |
by AnomalousMonk (Archbishop) on Nov 01, 2015 at 22:45 UTC | |
by Ppeoc (Beadle) on Nov 02, 2015 at 01:53 UTC | |
|
Re: Running out of memory while running this for loop
by GrandFather (Saint) on Nov 02, 2015 at 02:07 UTC |