here a variation which avoids reading the whole file in once, but instead line by line
use strict; use warnings; my @cache; my $n=4; while (my $line =<DATA>) { chomp $line; push @cache, $line; if (@cache >= $n) { print "@cache\n"; shift @cache; } } __DATA__ One Two Three Four Five Six Seven Eight Nine Ten
(Marshall++ was faster)
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re: Create n-grams from tokenized text file
by LanX
in thread Create n-grams from tokenized text file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |