in reply to Accessing cells in CSV files

my @array = <FILE>; stores the lines of your file in the array. They still need to be split into columns:

use strict; use warnings; use Data::Dumper; my @array = <DATA>; # now contains the rows print Dumper(\@array); $array[$_] = [ split /\s+/, $array[$_] ] for 0..$#array; # split lines + into columns print Dumper(\@array); print $array[0][0]; # does not look like CSV... __DATA__ organism O2_REQUIREMENT Domain Classification a.acidocaldarius Aerobe BACTERIA FIRMICUTES a.actinomycetemcomitans Facultative BACTERIA PROTEO

Replies are listed 'Best First'.
Re^2: Accessing cells in CSV files
by space_monk (Chaplain) on May 13, 2013 at 15:46 UTC
    Text::CSV_XS or Text::CSV will also handle tab separated values (TSV) like wot we appear to have 'ere.

    One of the reasons for using libraries is that the raw method you proposed will handle most cases but won't handle escaped/quoted forms if they exist in the data.

    If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
Re^2: Accessing cells in CSV files
by newbie1991 (Acolyte) on May 13, 2013 at 15:15 UTC
    Data::Dumper worked perfectly, thank you :) I usually work with txt files, and they're delimited properly so the splitting never occurred to me! As for the input file, it was handed to me in that particular format. I figured it wasn't comma-separated, but it isn't creating any issues right now, so I suppose it's alright (for now).