sub add_stuff_to_file { my ($filehandle, $stuff) = @_; ($stuff->isa('Iterable')) || die "Stuff must be iterable"; my $i = $stuff->iterator(); ($i->isa('Iterator')) || die "Stuff's iterator must be an Iterator"; while ($i->hasNext()) { print $filehandle $i->next(); } } #### serialize_stuff_to_file(Array::Iterator->new(@array)); serialize_stuff_to_file(ArrayOfArrays::Iterator->new(@array)); serialize_stuff_to_file(ArrayOfHashes::Iterator->new(@array)); serialize_stuff_to_file(Hash::Iterator->new(%hash)); serialize_stuff_to_file(HashOfHashes::Iterator->new(%hash)); serialize_stuff_to_file(HashOfArrays::Iterator->new(%hash)); serialize_stuff_to_file(Tree::Iterator->new($tree));