in reply to Re^3: Appending data to large files
in thread Appending data to large files

Hi
How do i go about inserting stuff from the csv, between END and $$$$? In the format:

END
> <Column 1>
Data 1
> <Column 2>
Data 2
$$$$

Etc.

In your example Kyle, 'insert csv stuff here' puts it after the $$$$ and i need it before.

Thanks.

* UPDATE *

Since my CSV is autogenerated at runtime, i do not know how many columns there will be, is there any way of using Text::CSV to extract a 'header' row?

TIA.
* END *

Replies are listed 'Best First'.
Re^5: Appending data to large files
by kyle (Abbot) on Jan 14, 2009 at 13:33 UTC

    Here's a self-contained runnable version of the code I posted in Re: Appending data to large files.

    my $record_end = qq{\$\$\$\$\n}; while (<DATA>) { next if ( $_ ne $record_end ); print "--CSV stuff--\n"; } continue { print; } __DATA__ example 1 example 2 END $$$$ example 3 example 4 END $$$$

    Here's the output:

    example 1 example 2 END --CSV stuff-- $$$$ example 3 example 4 END --CSV stuff-- $$$$

    Unless I've misunderstood your requirements, this is putting the CSV stuff right where you want it.

    Integrating that with the CSV-handling code I posted in Re^3: Appending data to large files (and the rest of your program, of course) is up to you.

    As for your question about headers, a quick look at the Text::CSV_XS documentation reveals a column_names method. That's what I'd try first. If that doesn't work out, then maybe a longer quick look would be required.