From jakesalomon at yahoo.com Wed Aug 4 12:57:31 2021 From: jakesalomon at yahoo.com (Jacob Salomon) Date: Wed, 4 Aug 2021 19:57:31 +0000 (UTC) Subject: [Philadelphia-pm] My first stab at loading a YAML file - and how it blows up in my face References: <2020096730.1822152.1628107051216.ref@mail.yahoo.com> Message-ID: <2020096730.1822152.1628107051216@mail.yahoo.com> 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.23rd Edition, Patched at 2009-10-01 Here's the YAML code I copy/pasted from one of the examples in the book:--------------------------------------? 1 --- !? 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);1011 1 == 1;? ? ?# Just a breakpoint12 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> nYAML 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 9Debugged 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 to another line - Commenting out that 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?) --+ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahpook at strawandfrost.com Wed Aug 4 13:10:51 2021 From: ahpook at strawandfrost.com (Ah Pook) Date: Wed, 4 Aug 2021 16:10:51 -0400 Subject: [Philadelphia-pm] My first stab at loading a YAML file - and how it blows up in my face In-Reply-To: <2020096730.1822152.1628107051216@mail.yahoo.com> References: <2020096730.1822152.1628107051216.ref@mail.yahoo.com> <2020096730.1822152.1628107051216@mail.yahoo.com> Message-ID: <34039fef-9167-c50a-7aa6-79334a495916@strawandfrost.com> On 8/4/21 3:57 PM, Jacob Salomon wrote: > ?5 use YAML; use YAML::XS From jakesalomon at yahoo.com Wed Aug 4 14:51:58 2021 From: jakesalomon at yahoo.com (Jacob Salomon) Date: Wed, 4 Aug 2021 21:51:58 +0000 (UTC) Subject: [Philadelphia-pm] My first stab at loading a YAML file - and how it blows up in my face In-Reply-To: <2020096730.1822152.1628107051216@mail.yahoo.com> References: <2020096730.1822152.1628107051216.ref@mail.yahoo.com> <2020096730.1822152.1628107051216@mail.yahoo.com> Message-ID: <103887539.1849854.1628113918852@mail.yahoo.com> Hi Folks again. I got two answers. Following both solved my problem: - Ah Pook pointed out that I should "use YAML::XM", not a naked YAML. - Dave Cross pointed out that I should be calling LoadFile(), not Load. The first time I used both, I got this error:bad tag found for hash: 'tag:clarkevans.com,2002:invoice' That's from the first line in the book's example: --- ! When I commented that out it loaded without a problem.? So why is it in the example?? For anyone who has that short book (84 pages), it is section 2.5, example 2.27.? But the bottom line for me is that now I'm able to look at the resulting hash.? Which will doubtless raise more questions but I'll jump off that bridge when I come to it. Thanks both and all. +----- Jacob Salomon -- jakesalomon at yahoo.com -------------------------+| 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?) --+ On Wednesday, August 4, 2021, 03:57:31 PM EDT, Jacob Salomon wrote: 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.23rd Edition, Patched at 2009-10-01 Here's the YAML code I copy/pasted from one of the examples in the book:--------------------------------------? 1 --- !? 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);1011 1 == 1;? ? ?# Just a breakpoint12 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> nYAML 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 9Debugged 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 to another line - Commenting out that 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?) --+ -------------- next part -------------- An HTML attachment was scrubbed... URL: