<?xml version="1.0" encoding="windows-1252"?>
<node id="451349" title="Re: How To: Make An Iterator" created="2005-04-25 17:13:08" updated="2005-06-20 22:54:06">
<type id="11">
note</type>
<author id="190134">
kelan</author>
<data>
<field name="doctext">
&lt;p&gt;
Here's another take on the first example that only returns one line at a time until all filehandles are exhausted and returns undef when that happens.
&lt;code&gt;
sub gen_fh_iterator {
  my ( $current, @fhs ) = @_;
  return sub {
    my $line;
    while ( ! defined $line &amp;&amp; @fhs ) {
      $line = &lt;$current&gt;;
      $current = shift @fhs
        if not defined $line;
    }
    return $line;
  };
}

my $file_iter = gen_fh_iterator( @fhs );
while ( my $line = $file_iter-&gt;() ) {
  print "$line\n";
}
&lt;/code&gt;
&lt;/p&gt;</field>
<field name="root_node">
451278</field>
<field name="parent_node">
451278</field>
</data>
</node>
