
dw.worker.bee
Novice
May 4, 2012, 8:34 AM
Post #1 of 3
(1228 views)
|
|
Arrays and delimiters, IFS help
|
Can't Post
|
|
Hello, I’m sure someone must have asked this… it seems like a very basic question but I guess I’m not searching on the right words or phrases. I have a file that has many rows in it. Each row has 75 columns. The delimiter that was used was hex 7f (“delete”, chr(127))… not sure why they did that but it was before my time. Now I have to find rows that have a null value in the 72 column. I’m loading the whole file in to an array called @data. I then iterate through the lines of the array with a foreach. But, I’m using brute force by loading 75 values in to variables using the split command and chr(127) as my delimiter. Isn’t it possible for me to put the whole line in another array, @line, set the IFS to be chr(127) and then check directly for $line[72]? This is for work so I felt uncomfortable posting the actual data. Below is a shorter version of the brute force method I’m using but it’s for only four columns. open(FH,"<$filename") or die "Could not open $filename: $!"; my @data = <FH>; close (FH); #...set the value for the column to sum up foreach my $inline (@data){ chomp $inline; my ($value1, $value2, $value3, $value4) = split(chr(127),$inline); print "Value1: $value1, Value2: $value2, Value3: $value3, value4: $value4\n"; <pseudo code> then evaluate if $value3 is null </pseudo code> } TIA DWWB
|