#!/usr/bin/perl
use warnings;
use strict;
my $content = qq(Three blind mice. Three blind mice. See how they ru
+n. See how they run. The butcher's wife came after them with a knif
+e, three blind mice.);
my @words = split(/\s+/, $content);
my @words_bi;
foreach (@words) { print "$_\n\n"; }
foreach (0..$#words) {
next if $_ < 1;
push(@words_bi, [ @words[$_-1 .. $_] ] );
}
foreach (@words_bi) { print "$_\n\n"; }
Which is resulting in
C:\Documents and Settings\admin\Desktop>perl words.pl
Three
blind
mice.
Three
blind
mice.
See
how
they
run.
See
how
they
run.
The
butcher's
wife
came
after
them
with
a
knife,
three
blind
mice.
ARRAY(0x225a20)
ARRAY(0x1853c64)
ARRAY(0x184780c)
ARRAY(0x18477dc)
ARRAY(0x18477ac)
ARRAY(0x184777c)
ARRAY(0x18475c0)
ARRAY(0x1847590)
ARRAY(0x1847560)
ARRAY(0x1847530)
ARRAY(0x1847500)
ARRAY(0x18474d0)
ARRAY(0x18474a0)
ARRAY(0x1847470)
ARRAY(0x1847440)
ARRAY(0x1847410)
ARRAY(0x18473e0)
ARRAY(0x18473b0)
ARRAY(0x1847380)
ARRAY(0x1847350)
ARRAY(0x1847320)
ARRAY(0x18472f0)
ARRAY(0x18472c0)
ARRAY(0x1847290)
ARRAY(0x184720c)
C:\Documents and Settings\admin\Desktop>
Thanks! |