graff has asked for the wisdom of the Perl Monks concerning the following question:
It appears (based on the module's pod), that the only way to start the csv parsing process with this module is to "open a csv file". So, since the "file" starts out as a scalar variable in my case, I'd like to know if there's some way to associate a "file handle" with the scalar value, so that I can initialize the Text::xSV object with that file handle as input.
In other words, I want to fill in the blank in the example snippet below:
BTW, please don't mention Text::CSV. That module has not been updated since it was uploaded to CPAN nine years ago. It's old, it's ugly, and it can only handle ASCII data (even accented characters in Latin1 will produce a "parse error", let alone anything like wide-characters).use strict; use Encode; # I'm getting utf8 data use LWP::Simple; use Text::xSV; my $fh; my $csv_url = "http://someplace/that/sends/data.csv"; my $content = decode( 'utf8', get( $csv_url )); # HERE IS THE BLANK TO FILL IN: # associate $fh (as file handle) with $content (as file data) # then: my $csv = Text::xSV( fh => $fh ); # or something like that(?) $csv->read_header; while ( $csv->get_row ) { # and so on }
I've already established that Text::xSV will handle utf8 wide character data without difficulty. I just would like to feed it input from a scalar (or an array of lines, whatever).
TIA
(updated the code snippet to fix the "Text::xSV->new" call, which originally had a couple different mistakes in it.)
(updated commentary on Text::CSV thanks to the behavior-modification powers of XP)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Treating a scalar as an "input file"
by Hofmator (Curate) on Aug 11, 2006 at 06:50 UTC | |
|
Re: Treating a scalar as an "input file"
by Ieronim (Friar) on Aug 11, 2006 at 06:56 UTC | |
|
Re: Treating a scalar as an "input file"
by davido (Cardinal) on Aug 11, 2006 at 15:11 UTC | |
|
Re: Treating a scalar as an "input file"
by diotalevi (Canon) on Aug 11, 2006 at 15:24 UTC |