Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: How to split big files with Perl ?

by james28909 (Deacon)
on Dec 26, 2014 at 19:01 UTC ( [id://1111423]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to split big files with Perl ?
in thread How to split big files with Perl ?

Well honestly it was like I said, it was purely untested code and was just for an example. I did not intend on it being a copy and paste example. All this does is reads the file then makes another file on the fly appending 001++ to it, thats all. I will however revise it and make any corrections so user can copy and paste it.
I stand corrected, it will take more than what i posted to be able to split it up. What I was considering was takeing a 10gb file, and split it into exactly 4gb chunks. I think that would require to read 1 byte at a time, and write the buf to outfile until a counter reaches the 4gb limit. That way it is not filling the memory with all this data at one time and would work smoothly. Ill see what i can cook up.
  • Comment on Re^3: How to split big files with Perl ?

Replies are listed 'Best First'.
Re^4: How to split big files with Perl ?
by ww (Archbishop) on Dec 26, 2014 at 19:11 UTC

    So perhaps you should adopt a policy of testing before posting?

    /me thinks so.



    check Ln42!

Re^4: How to split big files with Perl ?
by LanX (Saint) on Dec 26, 2014 at 19:15 UTC
    This code has too many obvious issues to be left without comment.

    Actually too many to be even listed.

    That's not a bashing - it's a warning for everybody who tries to copy that.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re^4: How to split big files with Perl ?
by Anonymous Monk on Dec 26, 2014 at 21:41 UTC

    I see you've updated your original node, but haven't marked it as updated. Please don't do that since now some of the replies don't make sense anymore, see here.

    This is still not correct: my $split_fh = $fh . 'split'; #creates 'filename.split' - don't use $fh, the filehandle, use a variable containing the filename here. Also print $out_file, $buf; - remove the comma.

    Reading the file one byte at a time is a slightly better approach than 2GB at a time, but probably still not very efficient - a buffer size of at least a few kilobytes will probably get you better performance.

Re^4: How to split big files with Perl ?
by Anonymous Monk on Dec 26, 2014 at 19:17 UTC

    Pseudocode is fine to demonstrate a concept, unfortunately, your concept needs some improvements to be practical, as mentioned above.

    I will however revise it and make any corrections so user can copy and paste it.

    I think that is an excellent exercise!

      Even revising it to "working state" produces errors as well. I wrote it very quickly as just an example anyway. Most of the code i post i do not plan on anybody using in their code, if anything it was just an example.

        You've been around here long enough. Consider your audience. The OP supposedly did a Google search on how to split a large file into parts and somehow missed the Unix split command. You only said your code was untested; more needed to be said to counter that level of cluelessness.

        1 Peter 4:10

        "Most of the code i post i do not plan on anybody using in their code"

        How are others supposed to know this? Perhaps a signature to reflect your position on this matter would be wise.

Log In?
Username:
Password:

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

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

    No recent polls found