Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Stucked in YAML::Tiny

by moritz (Cardinal)
on Jul 16, 2012 at 07:06 UTC ( #981979=note: print w/replies, xml ) Need Help??

in reply to Stucked in YAML::Tiny

I too get that error if reading from test.yaml fails. Then $yaml silently becomes undef, the later use of $yaml->[0] autovivifies it into an array reference, and then it's not a blessed reference, and calling write on it fails.

I suggest to use the LoadFile and DumpFile functions instead, which seem to do proper error checking.

Replies are listed 'Best First'.
Re^2: Stucked in YAML::Tiny
by ckj (Chaplain) on Jul 16, 2012 at 07:28 UTC
    On using LoadFile instead of read, it gives:
    "Failed to load YAML document from 'YAML::Tiny' at line 7 +"
    UPDATE The same code is working fine on unix machine, while on windows it's giving the same error. Not getting exactly what is the reason behind this. I checked but there also nothing was found. Perl code:
    use strict; use warnings; use YAML::Tiny; use Data::Dumper; # Create a YAML file my $yaml = YAML::Tiny->new; # Open the config $yaml = YAML::Tiny->read( 'test.yaml' ); #changing yaml file $yaml->[0]->{'order.create'}->{domain} = 'ckjckcjckj'; # Save the file $yaml->write('test.yaml');
    Yaml File:
    --- order.create: domain: sdfsdfsdfsdf
    The same code works in unix but gives error in windows "Can't call method "write" on unblessed reference at line 16.".
      In my code I use use YAML qw{LoadFile}, and it works fine on both Windows and *nix. YAML file example:
      --- version: 0.11 greek: - greek_plain - greek_italic csr: FontStyle: Italic: italic Position: Subscript: sub Superscript: sup gs: - EPS - PDF
      Can you try running perl debugger on your code and using s command after LoadFile call shows up to trace code inside LoadFile?
      Sorry if my advice was wrong.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981979]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2018-05-28 05:26 GMT
Find Nodes?
    Voting Booth?