Connecting Tech Pros Worldwide Forums | Help | Site Map

sorting through text with blank fields

Newbie
 
Join Date: Dec 2007
Posts: 1
#1: Dec 18 '07
I'm trying to pick off fileds from a line to insert them into a database. The problem that I'm having is that there is no delemiters between columns or set amount of spaces. Some columns have blank fields so this causes a problem.

Here is an example
Expand|Select|Wrap|Line Numbers
  1. "fieldone      fieldtwo fieldthree    fieldfour"
  2. "fieldone                   fieldthree     fieldfour" 
My script would read fieldtwo to be fieldthree instead of blank



here is part of the script where I attempt to sort through the fields

Expand|Select|Wrap|Line Numbers
  1. foreach my $line (@lines) {   
  2.             my @fields;
  3.               (@fields)  = split(/\s+/,$line);        
  4.             $fieldone        = $fields[0];        
  5.                                                $fieldtwo         = $fields[1]; 
  6.  
  7. }
Any help or insight would be greatly appreciated

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Dec 18 '07

re: sorting through text with blank fields


are the fields at least fixed lengths? If so you can maybe read the lines/fileds that way, if not, this will be difficult.
Reply