I'm trying to create a little app that shows a list of files on a web-page to be commented on.
It seems all to work. The web-page is generated via reading the content of a directory. I'd like to parse the list of images to_json to use it in a form. However I can't seem to get this parsing right.

"error" : "write_file '' - sysopen: No such file or directory at /Users/test/mytest/lib/mytest.pm line 35.\n"

Maybe someone can give me a hint what I'm doing wrong?
Gert

package mytest; use Dancer ':syntax'; use List::Util; use File::Slurp qw(read_file write_file); our $VERSION = '0.1'; set serializer => 'JSON'; get '/' => sub { template 'index' => { photos => AoH_imagelist(), }; }; #--------------------------------------------------------------------- # # function to read image-dir-gallery and create imagelist stored in Ao +H # #--------------------------------------------------------------------- sub AoH_imagelist { my @photos; my $images_dir = Dancer::FileUtils::path( setting('appdir'), 'public/images/galle +ry' ); opendir( my $dh, $images_dir ) || die "can't opendir $images_dir: +$!"; my @image_files = grep { $_ if /\.jpg$/i } readdir($dh); for my $i (@image_files) { push @photos, { file => "$i", caption => "" }; } #-------v this doesn't work? --------# my $filename = config->{mytest}{json}; my $json = -e $filename ? read_file $filename : '{}'; my $data = \@photos; #my $data = from_json $json; $data = { file => params->{file} , caption => params->{caption}, } +; # description to be added write_file $filename, to_json($data); #-------^-----------------------------# return \@photos; } true;

In reply to write_file to_json in Dancer app by GertMT

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.