in reply to data parsing

The above answers are fine, but the below just seems more logical to me, and it doesn't use any weird modules:
#!/usr/bin/perl my $i=0; #line number my $j=0; #field number my @array; while (<DATA>) { chomp; my @colon = split(":"); $j=0; $array[$i][$j] = $colon[0]; my @commas = split(",", $colon[1]); foreach my $field (@commas) { $j++; $array[$i][$j]=$field; } $i++; } ## Just for printing my $a=0; my $b=0; foreach my $fields (@array) { $b=0; foreach my $field (@$fields) { print "FIELD ($a,$b) = " . $field . "\n"; $b++; } $a++; } ## End printing section __DATA__ COLUMN_A: "Y","N" COLUMN_B: COLUMN_C: "something", "something else", "and more"

Replies are listed 'Best First'.
Re^2: data parsing
by davorg (Chancellor) on Jul 22, 2004 at 08:33 UTC

    This breaks if the data items contain embedded commas. That's why I used Text::ParseWords (which isn't a weird module, it comes as standard with Perl).

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg