in reply to problem with evaluating first line in a file
The easiest solution would be the check if your string is defined prior to upload, a la:
while(<LINES>){ if (m/^--/){ push (my @data, [$id,$line]); if (defined $line) { $self->_loaddb(table => 'TABLE', data=>\@data); } $line= undef; $id++; } else{ chomp(my $string = $_); $line.=$string; } }
Update: Or, if you want to "Drop empty records, without incrementing the id", you could
while(<LINES>){ if (m/^--/){ next unless defined $line; push (my @data, [$id,$line]); $self->_loaddb(table => 'TABLE', data=>\@data); $line= undef; $id++; } else{ chomp(my $string = $_); $line.=$string; } }
|
|---|