Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: split large CSV file >9.1MB into files of equal size that can be opened in excel

by stevieb (Canon)
on Sep 28, 2016 at 21:02 UTC ( [id://1172866]=note: print w/replies, xml ) Need Help??


in reply to Re: split large CSV file >9.1MB into files of equal size that can be opened in excel
in thread split large CSV file >9.1MB into files of equal size that can be opened in excel

Have you taken a look at the split csv files?

You're splitting in bytes, which means that unless your csv files are *very* reliably structured, you will likely break the file up into chunks that break full lines.

Say you have a file like this:

1,2,3,4,5

and a read statement like this:

read $fh, $chunk, 5;

You'll end up with split file one with:

1,2,3

and the second split file with:

,4,5

Which might not be what you wanted.

  • Comment on Re^2: split large CSV file >9.1MB into files of equal size that can be opened in excel
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: split large CSV file >9.1MB into files of equal size that can be opened in excel
by pryrt (Abbot) on Sep 28, 2016 at 23:17 UTC

    I think that's why the OP ran $chunk = <FH>; after the read(FH, $chunk, 10000); block: it reads whatever is left on the current line (or, if the read happened to end at the end of a line, it will read one extra line) and includes that extra bit in the same file. (This of course still assumes that there are no newlines supposedly protected by quotes in the source CSV, but with a name like "all_tags2", I am guessing that there aren't newlines in "tags".)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172866]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found