Perl - append text to cell if new cell has text -


my data this:

20110627 alpha beta gamma  217722 1425 1767 0.654504367955466 0.811585416264778 -0.157081048309312  

i using writeexcel module (i.e. tab2xls program) of john mcnamara :

use warnings; use strict; use spreadsheet::writeexcel; use scalar::util qw(looks_like_number); use spreadsheet::parseexcel;  use spreadsheet::parseexcel::saveparser; use spreadsheet::parseexcel::workbook;  if (($#argv < 1) || ($#argv > 2)) {     die("usage: tab2xls tabfile.txt newfile.xls\n"); }; open (tabfile, $argv[0]) or die "$argv[0]: $!";  $workbook  = spreadsheet::writeexcel->new($argv[1]); $worksheet = $workbook->add_worksheet(); $row = 0;  while (<tabfile>) {     chomp;     # split on single space     @fld = split('\s', $_);      $col = 0;     foreach $token (@fld) {         if (looks_like_number($token)) {             $worksheet->write($row, $col, $token);             $col++;         } else {             $worksheet->write($row, $col, $token);             #$col++;         }     }     $row++; } 

i want 2 things: firstly, keep text in 1 cell, , numbers in separate cells. code @ moment puts "alpha" in 1 cell, not put beta , gamma on cell (seems write not append text if there on cell, beta , gamma not appear @ in excel file produced).

secondly, in cases data provide, when there space in 2nd line, want move data of 2nd line in first line, each number in separate cell..

can me ? !

edit 1 :

i don't see answers :d thought of changing code following:

foreach $token (@fld) {         if (looks_like_number($token)) {             $worksheet->write($row, $col, $token);             $col++;         } else {             $totaltoken = $totaltoken." ".$token;             print "total token $totaltoken \n";             $worksheet->write($row, $col, $totaltoken);             $col++;         }     }     $row++; 

in case create variable $totaltoken appends text cells.. final text cell in line has text cells combined, need rid of previous text cells in line? ideas ?


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -