in reply to splitting files by number of words
#!/usr/bin/perl use strict; use Data::Dumper; my (@total_words, %record_file_of); my $counter = 0; my $num_of_files = 3; @total_words = split while (<DATA>); my $words_per_file = int( scalar @total_words / $num_of_files ); for my $i (0 .. $#total_words) { $counter++ if ( $i % $words_per_file == 0 ); push( @{ $record_file_of{$counter} } , $total_words[$i] ); } print Dumper \%record_file_of; __DATA__ This is a test of words. This should be divided into equal files.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting files by number of words
by Fletch (Bishop) on Aug 06, 2009 at 13:09 UTC | |
by si_lence (Deacon) on Aug 06, 2009 at 13:26 UTC | |
by bichonfrise74 (Vicar) on Aug 06, 2009 at 16:58 UTC |