<?xml version="1.0" encoding="windows-1252"?>
<node id="1005079" title="Re: Is it possible to get all tetra words with correct starting position using a better code within a loop?" created="2012-11-22 03:48:54" updated="2012-11-22 03:48:54">
<type id="11">
note</type>
<author id="880879">
space_monk</author>
<data>
<field name="doctext">
&lt;p&gt;You should look up [doc://substr]. (Update: [choroba] put a more detailed explanation while I was writing this, so see below)

&lt;p&gt;Alternatively, in the spirit of TMTOWDI, you also could adopt the following algorithm
&lt;ol&gt;
&lt;li&gt;split the words into an array characters
&lt;li&gt;terminate if less than 4 chars in array
&lt;li&gt;print the first 4 characters on the array
&lt;li&gt;remove (&lt;b&gt;shift&lt;/b&gt; the first character off the array
&lt;li&gt;go back to 2)
&lt;/ol&gt;

&lt;code&gt;

my $word = 'ABCDEFGH';
my @word = split //, $word;

my $pos = 1;
while (scalar(@word) &gt;= 4) {
   print @word[0..3]."==&gt; starting at $pos";
   shift @word;
   $pos++;
}

&lt;/code&gt;


&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-880879"&gt;
A Monk aims to give answers to those who have none, and to learn from those who know more.
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1005077</field>
<field name="parent_node">
1005077</field>
</data>
</node>
