Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Anonymous Monk
on Sep 28, 2016 at 20:40 UTC ( [id://1172865]=note: print w/replies, xml ) Need Help??


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

I got rid of the second if and it worked fine. Hopefully that doesn't break anything else.

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

Replies are listed 'Best First'.
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

    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.

      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://1172865]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found