#!/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
In reply to Re: Create n-grams from tokenized text file
by Marshall
in thread Create n-grams from tokenized text file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |