Sign in to PrePAN


User's Modules

IO::ReadHandle::Chain Chain read handles

This module provides a mechanism to chain any number of data sources together for reading through a single file handle. This is convenient if you have multiple sources of which some are very large and you need to pretend that they are all inside a single source.

One application is to pretend to wrap a huge file of XML elements in a root element so that it becomes acceptable to XML parsers such as XML::Twig, without actually having to create a modified copy of the huge file:

use IO::ReadHandle::Chain;
use XML::Twig;

$prefix = '<wrapper>';
$suffix = '</wrapper>';
$cfh = IO::ReadHandle::Chain->new(\$prefix, 'huge.xml', \$suffix);
$twig = XML::Twig->new( twig_handlers => { ... } );

NOTE: Read < for &lt; and > for &gt; above. I cannot figure out the Markdown to make them show up correctly.

LouisStrous@github 1 comment