in reply to Create n-grams from tokenized text file
#!/usr/bin/perl use warnings; use strict; my @tokens; my $n=2; #adjust as needed while (my $line = <DATA>) { chomp $line; push @tokens, $line; next if @tokens <$n; print "@tokens\n"; shift @tokens; } =prints: N=2.... Hello I I am am happy happy this this is is the the text text to to play play with N=3.... Hello I am I am happy am happy this happy this is this is the is the text the text to text to play to play with =cut __DATA__ Hello I am happy this is the text to play with
|
|---|