in reply to Re^4: Modifying CSV File
in thread Modifying CSV File

That ran in 4.194 on my dataset, which can be reduced by simplifying the regex even more.

open my $io, "<", "test.csv"; open my $oh, ">", "out.csv"; while (<$io>) { s{ ("[^""]+") }{ (my $one = $1) =~ tr{,}{-}; $one =~ tr{""}{}d; $o +ne; }xge; print $oh $_; }

runs in 3.229. All regex-based scripts will fail if

As long as you are absolutely certain that the CSV data is uniformly and consistently laid out as in these two lines, you are safe.

I would personally never take that risk, unless that two seconds are a problem. 5 seconds for 1.4 mln records is pretty fast, knowing it is always safe.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^6: Modifying CSV File
by roho (Bishop) on Jun 19, 2015 at 15:38 UTC
    Thanks for the regex mods. I am certain the CSV file will always be that format because it comes from another part of the system and if it were to change I would be the one asked to change it.

    "Its not how hard you work, its how much you get done."