Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
In this little chunk of your code:
# nonsense to know the file size if($ARGV[0]eq"-info"){ $len=length($file); print $len."\n"; exit 1; }
you are simply reporting the number of characters in the file name that the user has given on the command line. In order to state the actual byte count of data in the file, you want:
$len = -s $file; # not length($file)
I would recommend that since you are already using "my" declarations a lot, you should go ahead and include "use strict" as well. It might help catch some problems like:

$size is first mentioned in the "read()" call for the "-partir" operation; this means that you are passing an undefined value to "read()" for its "LENGTH" parameter, which means you don't read anything. Maybe you meant to put something like "$MAX_SIZE_PART*1024" there instead?

You never know what mistakes users will make on command line args, so I would advise more careful sanity checks on the @ARGV values. Consider using one of the Getopt modules. At a minimum, this:

if(($ARGV[2]=~m/-t/)==1){ $MAX_SIZE_PART=substr($ARGV[2],2); }
should be:
if ( $ARGV[2] =~ /^-t(\d+)/ ) { $MAX_SIZE_PART = $1; } else { die "Usage: blah blah\n"; }
Also, it looks like you are reading the entire content of the file into memory. Since this is for handling really big files, it would be better to read and write a chunk at a time, and not save each successive chunk by pushing them all onto an array.

Then there's also something very confusing about your use of $nro_partes (which probably should be spelled the same as the one declared at the top as "my $nro_parte;") -- you increment this by one on each read, but you compare it to $MAX_SIZE_PART.

Assuming that you have been using some version of this code that actually works, I believe that you have posted some different version, because I doubt that the code as originally posted will work.


In reply to Re: korta - split large files by graff
in thread korta - split large files by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-24 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found