<?xml version="1.0" encoding="windows-1252"?>
<node id="504625" title="Re: Count and List Items in a List" created="2005-11-01 11:09:01" updated="2005-11-01 06:09:01">
<type id="11">
note</type>
<author id="381608">
ikegami</author>
<data>
<field name="doctext">
&lt;c&gt;
while (&lt;FILE&gt;) {
    @zapschool = split (/\t/);
    if (m/zaps/i) {
        print NEWFILE "$zapschool[4]\n";        
    }
}
&lt;/c&gt;

is slower than

&lt;c&gt;
while (&lt;FILE&gt;) {
    if (m/zaps/i) {
        @zapschool = split(/\t/);
        print NEWFILE "$zapschool[4]\n";        
    }
}
&lt;/c&gt;

which can be made more readable as

&lt;c&gt;
while (&lt;FILE&gt;) {
    if (m/zaps/i) {
        my $zapschool = (split(/\t/))[4];
        print NEWFILE "$zapschool\n";        
    }
}
&lt;/c&gt;

And the solution is

&lt;c&gt;
my %count;

while (&lt;FILE&gt;) {
    if (m/zaps/i) {
        my $zapschool = (split(/\t/))[4];
        ++$count{$zapschool};
    }
}

foreach (keys(%count)) {
   print NEWFILE "$_: $count{$_}\n";        
}
&lt;/c&gt;
</field>
<field name="root_node">
504596</field>
<field name="parent_node">
504596</field>
</data>
</node>
