Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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.


Comment on Re: Stucked in YAML::Tiny
Select or Download Code
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 yaml_test.pl 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 Tiny.pm 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 yaml_test.pl 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-08-27 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls