I'm totally new to Perl, and I've been assigned some task... I have to read a tab separated file, and then do some operations with the data in a DB. The .tsv file is like this:
ID Name Date
155 Pedro 1988-05-05
522 Mengano 2002-08-02
So far I thought that creating a multidimensional array with the data of the file will be a good solution to handle this data later. So I read the file line by line, skip the item title columns and save the values in an array. However, I'm having difficulties creating this multidimensional array... this is what I've done so far:
#Read file from path
my @array;
my $fh = path($filename)->openr_utf8;
while (my $line = <$fh>) {
chomp $line;
# skip comments and blank lines and title line
next if $line =~ /^\#/ || $line =~ /^\s*$/ || $line =~ /^\+/ || $line =~ /ID/;
#split each line into array
my @aux_line = split(/\s+/, $line);
push @array, @{ $aux_line };
}
Obviously, last line is not working... how could be done to create an array of arrays this way? I'm little bit lost with references... And somebody can think of a better way to store this data we read from file? Thank you!
push @array, \@$aux_line;Text::CSVorText::CSV::Slurp. It can use the first line as field names, creates an array of hashes with field names as key and is nearly ready for inserting into a database viaDBIx::Classif the field names match the column names of the DB.DBD::CSV.DBIx::Classyou can use$schema->resultset('MyTable')->update_or_create($hashref_of_csv_record);Should fit in your case where you have the IDs in the TSV records.