The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


YAML::Perl - Pure Perl YAML Implementation


This is an early release of PyYaml ported to Perl. Don't even bother to try this version.

Still here?

This port is nearing completion. Most stuff works including:

    * Loading and dumping of basic types
    * Block and flow styles (JSON Loading)
    * Blessed hashes arrays and scalars
    * References
    * Tags
    * Detailed error messages
    * Lot's of new stuff like parser/emitter streaming api

You can play with it by using:

    ysh -MYAML::Perl


    * Review all code ported so far
    * Port diff from old copy of pyyaml to current version
    * Do all the utf8 related code porting that I've ignored
    * Port the pyyaml test suite to Perl
      * Get all tests to pass
    * Support esoteric Perl types like regexps and globs
    * Support the PyYAML tag resolution API
    * Write full documentation for YAML::Perl
    * Support YAML::Node from YAML::Perl


    use YAML::Perl;

    my $data = {
        name => 'Ingy döt Net',
        modules => [
            'YAML', 'YAML::Old', 'YAML::Perl', YAML::XS'

    my $yaml = <<'...';
    - YAML
    - YAML::Old
    - YAML::Perl
    - YAML::XS
    name: Ingy döt Net

    # Simple, familiar, Dump/Load API
    my $yaml2 = Dump $data;
    my $data2 = Load $yaml;

    # New, non-global dump API:
    my $yaml3 = YAML::Perl->new->dumper(%options)->dump($data);

    # New load API
    my $data3 = YAML::Perl->new->loader(%options)->open($yaml)->load();

    # New Streaming Parser/Emitter API
    my $yaml4;
    my $parser = YAML::Perl->new->parser->open($yaml);
    my $emitter = YAML::Perl->new-emitter->open($yaml4);
    while (my $event = $parser->parse()) {
        # Do various things with events here
    print $yaml4;


PyYAML is the most robust and correct YAML module for a dynamic language. It is (obviously) written in/for Python. This module is a complete port of PyYAML to Perl.


YAML::Parser reads a YAML serialization stream and produces events. YAML::Emitter takes YAML events and produces a YAML serialization stream.

Both of these modules allow you to process all the yaml/events at once, or do things one event at a time. If you call the YAML::Parser parse() method in list context, you get all the remaining event objects. If you call it in scalar context, you get the next event.

The YAML::Emitter emit() method takes one or more event objects as input arguments.


Ingy döt Net <>


Copyright (c) 2008, 2009. Ingy döt Net.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.