in reply to Filling In "The Gaps" in an Array
create a buffer for the value in question. if the value is null, use the buffered version. otherwise, modify the buffer to the current value.
there are edge cases i haven't dealt with, but you weren't that specific about functionality in that space. in any case, this should get you in the right direction.
#!/usr/bin/perl use strict; use warnings; $|++; my $buffer; while( my $record = <DATA> ) { my @items = split /\t/, $record, 5; '' ne $items[0] ? $buffer = $items[0] : $items[0] = $buffer; print join "\t", @items; } =pod prints: 1234 5 20021201 1 0 5678 0 20021202 0 0 5678 0 0 0 10 9120 10 20021211 0 0 6543 5 20021202 0 0 6543 0 0 0 5 6543 0 0 0 5 =cut __DATA__ 1234 5 20021201 1 0 5678 0 20021202 0 0 0 0 0 10 9120 10 20021211 0 0 6543 5 20021202 0 0 0 0 0 5 0 0 0 5
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Filling In "The Gaps" in an Array
by bivouac (Beadle) on Dec 12, 2002 at 05:01 UTC | |
|
Re: Re: Filling In "The Gaps" in an Array
by bivouac (Beadle) on Dec 12, 2002 at 21:55 UTC | |
by particle (Vicar) on Dec 12, 2002 at 23:40 UTC |