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
    Thanks so much for the posts! I'm certain that the approaches will help me out when I get back into the office tomorrow morning. I'll rework the code and repost my results if anyone else is interested. Thanks again.
Re: Re: Filling In "The Gaps" in an Array
by bivouac (Beadle) on Dec 12, 2002 at 21:55 UTC
    Man, my newbie-dom really manifested itself in the form of not being able to see the way you used operators as short hand. I went through my sources though and to put it in newbie terms: This...
    '' ne $items[0] ? $buffer = $items[0] : $items[0] = $buffer;
    ...is the same as this...
    if ('' ne $items[0]) { $buffer = $items[0] } else { $items[0] = $buffer }
    right? I think this is going to work out nicely. Thank you all so much for the help. --- you can't be what you were...so you better start being just what you are....

      your code example is correct. ?: is called the ternary operator. you can read about it in perlop

      ~Particle *accelerates*