The simple split text script was called by the teacher today to help me. A file is too large to be split. Leave a backup here. 01 #! /Usr/bin/perl-w02use strict; 03use warnings; 04 # split text file 05 # You can create folders 06 # csv07 08my $ csv = 'xxx.csv 'currently '; 09 print "File read from is '$ csv '. \ n "; 10my $ in_fh = read_text ($ csv); 11 12 # number of files 13my $ num_of_files = 15; 14 15 # number of lines 16my $ total_lines = 12465682; # Total number of lines 17 # Total number of lines of each text 18my $ lines = int ($ total_lines/$ num_of_files); 19 20my $ count = 0; 21my $ n = 1; 22my $ out_file = "xxx_rjn.csv"; 23 print "Create $ out_file... \ n "; 24my $ w_fh = write_text ($ out_file); 25 26 while (<$ in_fh>) {27 if ($ n <$ num_of_files and $ count = $ lines) {28 $ n ++; 29 $ count = 0; 30 close $ w_fh; 31 $ out_file = "xxx_20.n.csv"; 32 print "Create $ out_file... \ n "; 33 $ w_fh = write_text ($ out_file); 34} 35 print $ w_fh $ _; 36 $ count ++; 37} 38 close $ w_fh; 39 close $ in_fh; 40 41 print "Done! \ N "; 42 exit; 43 44 #================================================= =================45 # subroutions46 47 # Read the text file 48sub read_text {49 my $ filename = shift; 50 my $ fh; 51 open $ fh, '<', $ filename or die "Cannot open file '$ filename': $! "; 52 return $ fh; 53} 54 55 # Write a text file 56sub write_text {57 my $ filename = shift; 58 my $ fh; 59 open $ fh, '> ', $ filename or die "Cannot open file '$ filename': $! "; 60 return $ fh; 61}