Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: The future of Text::CSV_XS - TODO

by dipster (Novice)
on Oct 30, 2007 at 08:03 UTC ( #647987=note: print w/replies, xml ) Need Help??

in reply to The future of Text::CSV_XS - TODO

Firstly, what a great module, thanks! I've always found it reliable and effective.

It would be handy if string() returned the string read by getline().

Although this does seem to work...

use Text::CSV_XS; use IO::File; # tell/seek fails if i omit this line my $file = "1,2,3\n4,5,6\n7,8,9\n10,11,12\n13,14,15"; open (my $io, '<', \$file); # Open filehandle to in memory file my $csv = Text::CSV_XS->new(); while (1) { my $start = tell($io); my $colref = $csv->getline($io); last unless $colref; print "Array: @$colref\n"; my $length = tell($io) - $start; seek($io, $start, 0); read($io, my $string, $length); print "String: <$string>\n"; }

What do you think? Would it be possible for Text::CSV_XS to return the string more efficiently?

I've also wondered whether eol would always be limited to a finite set of predefined strings?

Thanks again.

Replies are listed 'Best First'.
Re^2: The future of Text::CSV_XS - TODO
by Tux (Abbot) on Oct 30, 2007 at 17:06 UTC

    That could be done, but not by default, as this has a big impact on performance, as now every getline () result has to be copied/stored in a location that string () can return to the user.

    The solution you post is only viable if the input stream is seek'able, and will not work on pipes. This is one of the reasons why this module is not capable of determining the line characteristics on the fly.

    Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://647987]
[james28909]: how can i write a while loop on one line (in a script) something like print "this\n" && print "that" && <DATA> && print the other\n" && next if /this matches/ while <DATA>?
[james28909]: i have tried with && and and and have tried to rearrange the functions as well to no avail
[shmem]: use parens to group expressions
[shmem]: you can't use next in a statement modifier
[shmem]: next requires a BLOCK

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-05-20 18:44 GMT
Find Nodes?
    Voting Booth?