Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

YAML problem

by luxs (Beadle)
on May 26, 2015 at 01:53 UTC ( [id://1127738]=perlquestion: print w/replies, xml ) Need Help??

luxs has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm sending data through the POST from HTML and then try to save it as YAML. This is a form to create data
<form action="/send.pl" method="POST"> <input name="product" size="50"> <input type="submit" value="Go"> </form>
here is the processing of the data in send.pl:
use YAML::Syck; use CGI::Fast ':standard'; while ( my $q = new CGI::Fast ) { my $data; $data->{'product'}=$q->param('product'); $data->{'product_test'}="test product"; #for test that YAML is working DumpFile( 'test.yml', $data ); print "Content-type: text/html\n\n"; print "q=".$q->param('product'); # this is for test only }
The result on the screen is perfect. q contains what ever it should contain. But the YAML file is bad.
--- product: ~ product_test: "test product"
Why the data are destroyed? UPD: The problem was solved by switching from YAML::Syck to YAML::Dumper library.

Replies are listed 'Best First'.
Re: YAML problem
by Anonymous Monk on May 26, 2015 at 03:05 UTC
    Well, the filename doesn't change, but its a relative filename ... so try an absolute filename
      No, this is not the case. Ive use unique file ne, file name with full path, or just put yaml file to the screen - results are alwsys wrong.

        I find no documentation in YAML::Syck how the library behaves in the case that DumpFile cannot write the file, for example due to missing permissions etc. . It may likely be that the new output is not written because the permissions between web server user are not sufficient.

Re: YAML problem
by GotToBTru (Prior) on May 26, 2015 at 15:34 UTC

    From the man page:

    This module has a lot of known issues and has only been semi-actively maintained since 2007. If you encounter an issue with it probably won't be fixed unless you offer up a patch in Git that's ready for release.

    You might want to investigate your other options.

    Dum Spiro Spero
      Is there are any other good YAML libraries for perl?

        If you don't insist on YAML, try JSON::XS, that will use JSON instead. JSON is also plain text, but (IMHO) more readable than YAML.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        I have had no problems with YAML, even though its docs claim it is still an alpha release and based from "a very old pre [YAML] 1.0 spec."

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found