<?xml version="1.0" encoding="windows-1252"?>
<node id="968934" title="Re: foreach only for a section of a list" created="2012-05-04 11:01:32" updated="2012-05-04 11:01:32">
<type id="11">
note</type>
<author id="712372">
kennethk</author>
<data>
<field name="doctext">
There are a few ways.  You can use C-style [doc://perlsyn#For-Loops]:
&lt;p&gt;&lt;c&gt;for (my $i = 0; $i &lt; @somewords -1; $i++) {
  print " $somewords[$i];\n"
}&lt;/c&gt;
You can use [doc://perldata#Slices]:
&lt;p&gt;&lt;c&gt;foreach $core (@somewords[0 .. $#somewords-1]) {
  print " ${core};\n"
}&lt;/c&gt;
Or, in some cases, it makes sense to use [doc://perlsyn#Loop-Control]:
&lt;p&gt;&lt;c&gt;my $i = 0;
foreach my $core (@somewords) {
  next if ++$i == @somewords;
  print " ${core};\n"
}&lt;/c&gt;
&lt;p&gt;TIMTOWTDI&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-712372"&gt;
&lt;p&gt;#11929 First ask yourself `How would I do this without a computer?'  Then have the computer do it the same way.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
968933</field>
<field name="parent_node">
968933</field>
</data>
</node>
