in reply to Re: Out of memory
in thread Out of memory
Thanks for the input - both piece of code (from both monks)worked! Now I know to ditch my books and come here for enlightenment. But its not just the number of words I'm after, I need to have the file content in memory to parse and extract all proper names (i.e 2 or more consecutive words)from it.
I guess I'll have to go the sysread way.
my $buffer ; while (sysread TEXT, $buffer, $buffer_size) { ## This will use tr to count fast for you: $words += ($buffer =~ tr/ +\n+,://) ; }
My entire code (if I dare show :)) looked something like this before:
$fname = "haystack.test"; open(TEXT, "<$fname")|| die "could not open file: $fname\n"; while (<TEXT>) { $txt .= $_; } @words = split (/[ +\n+\,\:]/, $txt); $len = @words; print "LEN = $len\n"; close (TEXT); $i =0; while( $i< $len) { my $flag2 = 1; my $sptr = my $eptr = $words[$i]; if($sptr =~ /^[A-Z][a-z]+/ ) { $eptr = $words[$i+1] ; if($eptr =~ /^[A-Z][a-z]*/ && $i< $len) { $i++; $sptr = $words[$i]; $eptr = $words[$i+1] ; $flag2 = 0; while($eptr =~ /^[A-Z][a-z]*/ && $i < $len) { $i++; #print "I =$i\n"; $sptr = $words[$i] ; $eptr = $words[$i+1] ; } if (flag2 ne 1) { print"\n";} } else {$i++; } else { $i++;} } print"\n";
So do you think i'll be alright loading all the words in an array? Or is there a better way?
Thanks
J
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Out of memory
by Abigail-II (Bishop) on Aug 19, 2002 at 13:21 UTC | |
by Anonymous Monk on Aug 19, 2002 at 13:54 UTC | |
by Anonymous Monk on Aug 19, 2002 at 15:14 UTC | |
|
Looking for proper names in text
by graff (Chancellor) on Aug 20, 2002 at 04:13 UTC |