Other tinhg, your regexp (RE) are wrong! [] is to make a group of characters! For example, \w is the same of [a-zA-Z0-9], and you don't need to put the "\" before "," and ":" too. I thing that the right RE inside split is: / +\n+,:/
Since you are using a big file (150M) win speed is good too! Don't read the file using <TEXT>, use read() or sysread(), because <> will scan the data and look for \n, and only after this return the data!
You dont need to use this: my @array = (); to clean the array! Because when you make: my @array ; you already have cleanded the array!
Try this code for your script:
"The creativity is the expression of the liberty".$fname = "$0"; open(TEXT, "<$fname")|| die "could not open file: $fname\n"; ## Let's read 100KB per time. my $buffer_size = 1024*100 ; my ($buffer,$words) ; while (sysread TEXT, $buffer, $buffer_size) { ## This will count fast for you: my @c = ($buffer =~ /( +\n+,:)/gs) ; $words += @c ; } close TEXT; print "Length: $words\n" ; exit;
In reply to Re: Out of memory
by gmpassos
in thread Out of memory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |