Thanks to everyone for their help on this problem. I finally ended up using the following: #!perl use warnings; use strict;
my @empty = (); my @headings = ();
Aggregate variables created with my() are empty by default so assigning an empty list to them is redundant.
my $sum;
open INDEX, "> fieldcontents.txt" or die "can't create fieldcontents.txt $!"; open INPUT, "<lv1.txt" or die "can't open data file: $!"; {
while (<INPUT>) { if ($. == 1) { chomp; # remove newline @headings = split /\t/; # get each of the headings @empty = @headings; } next if $. == 1 ; chomp; # remove newline
There is no need to chomp() or compare $. twice.
while (<INPUT>) { chomp; # remove newline if ($. == 1) { @headings = split /\t/; # get each of the headings @empty = @headings; next; }
my @fields = split /\t/; # get each of the fields
for (my $i = 0; $i <= $#fields; $i++) {
The usual Perl way to write that is:
for my $i ( 0 .. $#fields ) {
if (length($fields[$i]) >= 1) { #look for fields with no value
$empty[$i] = ""; #assign flag to new array } } }
foreach (@empty){ if( $_ ){ print INPUT "$_\n"; } }
close INPUT; }
close INDEX;
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>