Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

YAML::TINY and module install test

by porcustal (Initiate)
on Feb 11, 2009 at 02:02 UTC ( #742940=perlquestion: print w/ replies, xml ) Need Help??
porcustal has asked for the wisdom of the Perl Monks concerning the following question:

So I just installed YAML::Tiny and can't get it to work, as I've only installed maybe one other module before I'm very unsure if its working or just me.
make test and make install both passed with no issues, so i'm leaning towards some silly code mistake i'm making.. I have this script to test:

#!/usr/bin/perl use strict; use YAML::Tiny; my $orders_yam = "./customers.yml"; #### TEST a YAML file my $yaml = YAML::Tiny->new(); ### Open the config my $yaml = YAML::Tiny->read( "$orders_yam" ) or die "Couldn't read fil +e: errno($!) : errstr =", YAML::Tiny->errstr; my $root = $yaml->[1]->{email}; print "\nFirst item is: $root\n";

The customers.yml file goes like:

#customers and order's --- email: goose@gmail.com orders: - order: wb090130 item: 0001 item: 0002 price: 3.98 downloads: 3 - order: wb090131 item: 0003 item: 0004 price: 3.98 downloads: 5 total: 7.96 --- email: cowboy@bebop.com
Learning perl, one %hash at a time....

Comment on YAML::TINY and module install test
Select or Download Code
Re: YAML::TINY and module install test
by Anonymous Monk on Feb 11, 2009 at 02:12 UTC
    So how is it failing? Maybe you want
    YAML::Tiny->read( "$orders_yam" ) or die "Couldn't read file: errno($!) : errstr =", YAML::Tiny->errstr;

      Heh yea thanks, some error reporting would be good :) I get this with the error code added...

      sg:~/desktop % perl yaml.pl Couldn't read file: errno() : errstr =Stream does not end with newline + character at yaml.pl line 10.
      I don't know what this is refering to.. i haven't used the read() function much, but why is it asking for this mysterious new-line?

      I'm on an Mac OS X computer btw.

      Learning Perl, one %hash at a time....
        YAML::Tiny seems to think your yaml file isn't properly formatted. Since you're on OS X, and ysh thinks your yaml is fine, its probably a bug in YAML::Tiny (missing binmode). You could probably work around it with
        use open IN => ':bytes'; use YAML::Tiny; ....
        If that fixes it, you should report the bug.
Re: YAML::TINY and module install test
by gnosti (Friar) on Feb 11, 2009 at 05:21 UTC
    At first glance, your YAML appears incorrectly formatted. The - order lines should be indented two spaces. I'm also dubious about your having two item: fields under - order. Do you know that those are hash keys, and that the second will tend to clobber the first?

    I wonder if you've read sufficiently about the modules you are using. Perhaps you need to try going from perl data structures to YAML, to see what the formatting should be.

    I would try the following (possibly valid) YAML:

    --- email: goose@gmail.com orders: - order: wb090130 item: 0001 item: 0002 price: 3.98 downloads: 3 - order: wb090131 item: 0003 item: 0004 price: 3.98 downloads: 5 total: 7.96 ...
    UPDATE: YAML should end with '...'

      Well I think your right I need to study the format of the expected yaml file. I used your excellent suggestion and created lines to write out a yaml file which worked, and which i could read, so it was my bad.

      But the documention of the module leaves alot to be desired, so for now i'll just stick with rolling my own storage flatfile...

      manythanks for all the help!



      Learning Perl, one %hash at a time....
        But the documention of the module leaves alot to be desired, so for now i'll just stick with rolling my own storage flatfile... manythanks for all the help!

        That sounds like you're giving up :) its not easy to get ahead reinventing wheels. http://yaml.org/
        AppConfig...

        Yes I plan on coming back to it, :) but for now its easier to make a data file I understand than trying to understand someone else's creation... I'm not doing anything complicated atm. Data::dump looks like a quick to understand module if i need something more robust, app::config seems like it might be worth looking at too sometime.



        Learning Perl, one %hash at a time....

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://742940]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-10-25 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls