Jacob Salomon on 4 Aug 2021 15:17:37 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Philadelphia-pm] My first stab at loading a YAML file - and how it blows up in my face


Hi Folks (capitalized!  ;-)

I'm a member of the ny.pm group, with Jim Keenan.  (Just for some identification)

In my most recent contract, the team leader (call him Steve) implemented a lot of great stuff using YAML files as a sort of registry for the applications.  So now I have the time to play with that stuff and try my own hand at it.  I'm using this book as a starting point:
YAML Ain’t Markup Language (YAML™)
Version 1.2
3rd Edition, Patched at 2009-10-01

Here's the YAML code I copy/pasted from one of the examples in the book:
--------------------------------------
  1 --- !<tag:clarkevans.com,2002:invoice>
  2 invoice: 34843
  3 date : 2001-01-23
  4 bill-to: &id001
  5   given : Chris
  6   family : Dumars
  7   address:
  8     lines: |
  9       458 Walkman Dr.
 10       Suite #292
 11     city : Royal Oak
 12     state : MI
 13     postal : 48046
 14 ship-to: *id001
 15 product:
 16   - sku : BL394D
 17     quantity : 4
 18     description : Basketball
 19     price : 450.00
 20   - sku : BL4438H
 21     quantity : 1
 22     description : Super Hoop
 23     price : 2392.00
 24 tax : 251.42
 25 total: 4443.52
 26 comments:
 27   Late afternoon is best.
 28   Backup contact is Nancy
 29   Billsmer @ 338-4338.
--------------------------------------
(I've tried to paste that in Courier font so that the indents stay consistent.)

Here is my Perl code:
----------------------------------------
 1 #!/usr/bin/perl -w -d
 2 # practice1.pl - My first practice yaml code
 3 #
 4 use strict;
 5 use YAML;
 6 use Data::Dumper;
 7
 8 my $yamfile = "./invoice.yaml";     # Play with this one firs
 9 my $yamlref = Load($yamfile);
10
11 1 == 1;     # Just a breakpoint
12 exit 0;
----------------------------------------

 (Again, I pasted that in Courier font.  But Yahoo mail is not always cooperative.)

And what happens when I issue that load call?
----------------------------------------
main::(./practice1.pl:9):       my $yamlref = Load($yamfile);
  DB<1> n
YAML Error: Expected separator '---'
   Code: YAML_PARSE_ERR_NO_SEPARATOR
   Line: 1
   Document: 2
 at /usr/share/perl5/YAML/Loader.pm line 78.
 at /usr/share/perl5/YAML/Mo.pm line 16.
        YAML::Mo::__ANON__[/usr/share/perl5/YAML/Mo.pm:17](YAML::Loader=HASH(0x1485c30), "YAML_PARSE_ERR_NO_SEPARATOR")
            called at /usr/share/perl5/YAML/Loader.pm line 78
        YAML::Loader::_parse(YAML::Loader=HASH(0x1485c30)) called at /usr/share/perl5/YAML/Loader.pm line 24
        YAML::Loader::load(YAML::Loader=HASH(0x1485c30), "./invoice.yaml") called at /usr/share/perl5/YAML.pm line 33
        YAML::Load("./invoice.yaml") called at ./practice1.pl line 9
Debugged program terminated.  Use q to quit or R to restart,
----------------------------------------
My searches have turned up lots of similar problems but no solution I could easily grok.  Can someone please point out what I'm doing wrong in the Yaml?  I may have pasted something incorrectly but the --- separator is there at the top.

BTW I have tried:
  • Moving that <tag> to another line
  • Commenting out that <tag> altogether
  • Adding --- separator at the bottom of the YAML file
  • Adding ... there instead of the ---
None of these fixed the "YAML_PARSE_ERR_NO_SEPARATOR" error.

I may post this on Perlmonks as well (I see it is addressed there) but I don't yet want to advertise my incompetence that widely. :-))

Thanks much for any help here.

+----- Jacob Salomon --------------------------------------------------+
| The first lesson of economics is scarcity: there is never enough of  |
| anything to fully satisfy all those who want it. The first lesson of |
| politics is to disregard the first lesson of economics.              |
+------------------------------ Thomas Sowell (Is Reality Optional?) --+
_______________________________________________
Philadelphia-pm mailing list
Philadelphia-pm@pm.org
https://mail.pm.org/mailman/listinfo/philadelphia-pm