in reply to Parsing a table with variable columns on each line

while (<>) { chomp; my @fields = split /\t/; for ( splice(@fields, 3) ) { print(join("\t", @fields, $_), "\n"); } }
or
while (<>) { (my $common, $_) = /^((?:[^\t]*\t){3})(.*)/; for ( split /\t/ ) { print("$common\t$_\n"); } }

Replies are listed 'Best First'.
Re^2: Parsing a table with variable columns on each line
by Anonymous Monk on Oct 23, 2009 at 16:32 UTC
    Thank you Ikegami,
    The outputs aren't quite what I had in mind but I couldn't really represent my data accurately. I think now with a starting point I can fiddle about and get somewhere with this file.

    Thank you for you time and wisdom.
    Have a nice weekend.

      The outputs aren't quite what I had in mind

      I don't understand. The output is exactly what you requested.

      Apples 0.5 -10 Emma:17:15:14:18 Apples 0.5 -10 Peter:2:7:4:1 Pears 0.7 -12 Alex:101:144:110:111 Oranges 0.8 -14 Shan:12:14:9:57 Oranges 0.8 -14 Heena:65:17:15:24 Oranges 0.8 -14 Rachel:1:5:18:54

      ...except for the second snippet. It had a bug that's now fixed.

        Thank you. This is working now.