Article 2205 of comp.lang.perl: Xref: feenix.metronet.com comp.lang.perl:2205 Newsgroups: comp.lang.perl Path: feenix.metronet.com!news.utdallas.edu!corpgate!bnrgate!nott!torn!utnut!cs.utexas.edu!uunet!infonode!ingr!b17news!tamills@ingr.com From: tamills@ingr.com Subject: MSDOS Perl - Why does read() only give back 51 bytes? Message-ID: <1993Apr16.201010.17261@b17news.b17a.ingr.com> Sender: usenet@b17news.b17a.ingr.com (USENET) Reply-To: tamills@ingr.com Organization: Cartographic Applications, Intergraph Date: Fri, 16 Apr 1993 20:10:10 GMT Lines: 115 I wrote this script for breaking up files into arbitrary sized chunks. The primary use for me would be transporting large files on floppies. My problem is that though it works under Unix, it won't work under MSDOS. The read() function is returning only 51 bytes at a time. I also tried sysread() just in case it might work. No luck. I've included it below in case anyone wants to take a critical crack at it or would find it useful. I'd appreciate if someone could address my problem. Thanks! === /usr/local/perlsrc/cleave ========== CUT HERE ========================= #!/usr/local/bin/perl ########################################################################### # # Cleave # # NO COPYRIGHT. If you can't write a baby program like this yourself, # maybe you should steal it. :-> # # I brazenly stole this idea from Thom Vaught in a fit of thought # plagerism. It breaks up a file into a certain number of files or # in as many files of the given size as needed. # # Type cleave with no arguments to see a usage string. # $trace = 0; &db("ARGV = @ARGV\n"); $usage = "\nUsage:\t$0 -n | -s \t\t-f [infile]\n"; # # Get arguments from command line # require 'getopts.pl'; &Getopts('tn:s:f:'); $filename = shift @ARGV; $trace = $opt_t ? 1 : 0; # # Jump through several hoops to test the arguments given and bitch if # any aren't correct. # ($opt_f && (length($opt_f) <= 8)) || push(@ERRS, "You must provide a file name base (<= 8 chars) for your new file names.\n"); $opt_n && $opt_s && push(@ERRS, "You can't use both size and number.\n"); $opt_n || $opt_s || ($opt_n = 2); $opt_s && (($opt_s - int($opt_s)) > 0) && push(@ERRS, "If you give the size of pieces, it must be a whole number.\n"); $opt_n && (($opt_n - int($opt_n)) > 0) && push(@ERRS, "If you give the number of pieces, it must be a whole number.\n"); die @ERRS, $usage if $#ERRS >=0; # # Get the input file opened and set up a couple of variables that # we'll use to control reading and writing of files. $filename || ($filename = "-"); # If the filename isn't given, we get input # from STDIN. &db("filename = $filename\n"); open(F, $filename) || die "Could not open $filename: $!\n"; if ($filename eq "-") { undef $fsize; &db("fsize was undef'd\n"); die "Using standard input requires the size flag.\n\n$usage" if (! $opt_s); } else { $fsize = -s F; &db("fsize = $fsize\n"); } $chunk_size = $opt_n ? int(($fsize/$opt_n) + 1) : $opt_s; &db("chunk_size = $chunk_size\n"); # # Now, the rubber meets the road. # for ($i = 0; ; $i++) { &db("i = $i\n"); $oname = sprintf(">%s.%.3d", $opt_f, $i); &db("output filename = $oname\n"); open(O, $oname) || die "Whoa! Why can't I open $oname ???\n\n"; read(F, $inchunk, $chunk_size); print(O $inchunk); close (O); last if eof(F); } sub db { print @_ if $trace; } === /usr/local/perlsrc/cleave ========== CUT HERE =========================