Im reading from a file and depends on the length of the file, it will write to google spreadsheet. I have many files which range from 5 elements in an array to 200 elements(as u can see in the example I only have up to 15) elements. Right now its taking me a long time to write the code, is there an easier way to write it? Below is the part of the code of the looping strucure:
#$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++;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.