Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have an html file which is having a data as given below
Section 241(b)(3)(A)-(C) Data.
So in the output csv i should need rows as given below
Section 241(b)(3)(A) Data Section 241(b)(3)(B) Data Section 241(b)(3)(C) Data
ie from A to C i need 3 rows.Please help me in doing this. Thanks.

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: Writing into a csv
by moritz (Cardinal) on Dec 01, 2011 at 13:29 UTC
Re: Writing into a csv
by Anonymous Monk on Dec 01, 2011 at 13:42 UTC
Re: Writing into a csv
by TJPride (Pilgrim) on Dec 02, 2011 at 02:47 UTC
    Grandfather - his original post had none of that. He must have edited it later.

    Solution code - requires Text::CSV.

    use Text::CSV; use strict; use warnings; my ($in, $inhandle, $out, $outhandle, $csv, @fields, $prefix); $in = 'test.csv'; open ($inhandle, "<$in") || die; $out = 'testout.csv'; open ($outhandle, ">$out") || die; $csv = Text::CSV->new(); while (<$inhandle>) { chomp; $csv->parse($_); @fields = $csv->fields(); if ($fields[0] =~ s/\(([A-Z])\)\-\(([A-Z])\)$//) { $prefix = $fields[0]; for ($1..$2) { $fields[0] = "$prefix($_)"; $csv->combine(@fields); print $outhandle $csv->string() . "\n"; } } else { print $outhandle "$_\n"; } }
Re: Writing into a csv
by TJPride (Pilgrim) on Dec 01, 2011 at 14:28 UTC
    -- for total lack of clarity in your post. How about you put your data on a web site somewhere and supply a link so we can actually take a look at what you're talking about? Preferably with a sample of what you want it to come out looking like.

      An appropriate web site is PerlMonks, right along with the question, the sample code, broken output and expected output.

      True laziness is hard work