Jonathan Paton wrote:
Dear All,

Hello,

Given the requirement that we are looking for unused columns, as soon
as we have seen all columns we can exit.  I would do:

my %look_for;

my @header = split /\t/, <DATA>;

You don't chomp the input here which may foul up your output at the end.


for my $column (0 .. $#header - 1) {
    $look_for{$column} = undef;
}

You have an off-by-one error because you are using $#header - 1 which will ignore the last column. You could use a hash slice to accomplish the same thing:


@look_for{ 0 .. $#header } = ();


while (<DATA>) {
    chomp;
    my @data = split /\t/;

    for my $column (keys %look_for) {
        if ($data[$column] ne "") {
            delete $look_for{$column};
        }
    }

    last if keys %look_for == 0;
}

for my $column (keys %look_for) {
    print "Field" . $header[$column] . "is empty\n";
^ ^
You should include spaces to separate those three words. If $header[$column] has a newline then "is empty\n" will print on the next line.



}

[All above untested... E&OE]

With those corrections it appears to work as advertised. :-)


John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to