AllPaoTeam has asked for the wisdom of the Perl Monks concerning the following question:
#$col_length depends on the intial read in of the file to see +how many elements in each line $count = 6; while (<GOOG>) { @test1 = split(/ /); if ($col_length == 5) { $googlesheet->batchupdate_cell( {row => $count, col => 2, input_value => $test1[0]}, {row => $count, col => 3, input_value => $test1[1]}, {row => $count, col => 4, input_value => $test1[2]}, {row => $count, col => 5, input_value => $test1[3]}, {row => $count, col => 6, input_value => $test1[4]} ); } elsif ($col_length == 10) { $googlesheet->batchupdate_cell( {row => $count, col => 2, input_value => $test1[0]}, {row => $count, col => 3, input_value => $test1[1]}, {row => $count, col => 4, input_value => $test1[2]}, {row => $count, col => 5, input_value => $test1[3]}, {row => $count, col => 6, input_value => $test1[4]}, {row => $count, col => 7, input_value => $test1[5]}, {row => $count, col => 8, input_value => $test1[6]}, {row => $count, col => 9, input_value => $test1[7]}, {row => $count, col => 10, input_value => $test1[8]}, {row => $count, col => 11, input_value => $test1[9]} ); } elsif ($col_length == 15) { $googlesheet->batchupdate_cell( {row => $count, col => 2, input_value => $test1[0]}, {row => $count, col => 3, input_value => $test1[1]}, {row => $count, col => 4, input_value => $test1[2]}, {row => $count, col => 5, input_value => $test1[3]}, {row => $count, col => 6, input_value => $test1[4]}, {row => $count, col => 7, input_value => $test1[5]}, {row => $count, col => 8, input_value => $test1[6]}, {row => $count, col => 9, input_value => $test1[7]}, {row => $count, col => 10, input_value => $test1[8]}, {row => $count, col => 11, input_value => $test1[9]}, {row => $count, col => 12, input_value => $test[10]}, {row => $count, col => 13, input_value => $test[11]}, {row => $count, col => 14, input_value => $test[12]}, {row => $count, col => 15, input_value => $test[13]}, {row => $count, col => 16, input_value => $test[14]} + ); } $count++;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need to find a more efficient way to write if/elsif in loop
by toolic (Bishop) on Sep 05, 2014 at 15:54 UTC | |
by AllPaoTeam (Sexton) on Sep 05, 2014 at 16:19 UTC | |
by toolic (Bishop) on Sep 05, 2014 at 16:51 UTC | |
by AnomalousMonk (Archbishop) on Sep 05, 2014 at 17:36 UTC | |
by AllPaoTeam (Sexton) on Sep 05, 2014 at 16:51 UTC | |
|
Re: Need to find a more efficient way to write if/elsif in loop
by AppleFritter (Vicar) on Sep 05, 2014 at 15:56 UTC | |
by AllPaoTeam (Sexton) on Sep 05, 2014 at 16:02 UTC |