Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've recently been toying with moving some Perl code into a web setting using Dancer. Below is some code to generate a list of files in a specific folder and then take in the user's selection. However, when run through the browser it simply generates a blank page. What's confusing for me is that the unrelated code following the template determines whether or not it will generate the page.

This works:

any ['get', 'post'] => '/parsescript' => sub { template 'test.tt'; };

This doesn't:

any ['get', 'post'] => '/parsescript' => sub { template 'test.tt'; my @filelist; my $rawtext; my $rootdir = 'C:\\Users\\Nathaniel\\Corpus\\'; opendir (DIR, $rootdir) or die $!; while (my $file = readdir(DIR) ) { next unless (-f "$rootdir/$file"); next unless ($file =~ /\.txt$/); push @filelist, $file ; } };

Thanks for your help!

UPDATE:Thank you to everyone for their help. As always, one of the best results of posting on here is learning about all the other small mistakes or inefficiencies in your code unrelated to the code-breaking problem. Special thanks to CountZero, it would probably have taken me months to realize template must go at the end of the sub. Turns out my biggest mistake (which I omitted in my post as it seemed irrelevant) was trying to pass a list (rather than a reference to a list) to the template. Thank you all!


In reply to Dancer not displaying Template by nathaniels

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found