in reply to The best way to split tab delimited file

if the comma is a fixed aspect of this file, then
@fields = split (/[^,]\t/,$record)
would probably do what you need, but BioLion's suggestion above might make your life easier further down the road, as more "little quirks" emerge in the data

Replies are listed 'Best First'.
Re^2: The best way to split tab delimited file
by johngg (Canon) on Nov 16, 2009 at 23:29 UTC

    By placing the comma in a negated character class you lose any character preceding the tab, apart from a comma, in the resultant array because it becomes part of the split term. Placing the comma in a negative zero-width look-behind, as gmargo does here, the characters are retained.

    $ perl -le ' > $txt = qq{abc\tdef,\tghi\tjkl\tmno}; > print for split m{[^,]\t}, $txt; > print q{-} x 20; > print for split m{(?<!,)\t}, $txt;' ab def, gh jk mno -------------------- abc def, ghi jkl mno $

    I hope this is of interest.

    Cheers,

    JohnGG