This is not tested.
my $reader = YAML::ReadStream( $file_handle ); while ( my $document = $reader->() ) { ... } sub YAML::ReadStream { my $handle = shift; my $buffer; return sub { if ( eof $handle ) { undef $buffer; return undef; } else { return YAML::_ReadOneDocument( $handle, \ $buffer ); } }; } sub YAML::_ReadOneDocument { my $handle = shift; my $buffer = shift; while ( 1 ) { if ( eof $handle ) { return YAML::Load( $$buffer ); } read $handle, $$buffer, 8192, length $$buffer; my $yaml_header_position = index $$buffer, "\n---", length( "- +--" ); if ( $yaml_header_position >= 0 ) { my $doc = substr $$buffer, 0, $yaml_header_position, ''; return YAML::Load( $doc ); } } }
In reply to Re: YAML: reading a file w/ multiple docs in it, doc by doc
by diotalevi
in thread YAML: reading a file w/ multiple docs in it, doc by doc
by water
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |