Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Answering the (original) question ("Does Perl have an equivalent to PHP's <code>readline()</code> function ... ?"), the answer is "the angle bracket syntax":</p> <pre><code>open my $fh, '&lt;', '/path/to/file.txt'; while (my $line = &lt;file&gt;) { print $line; } </code></pre> <p>Getting the content-length with this method isn't necessarily easy, though, so I'd recommend staying with <code>Tie::File</code>.</p> <hr> <p><strong>NOTE</strong></p> <p>Using:</p> <pre><code>for my $line (&lt;$filehandle&gt;) { ... } </code></pre> <p>(as I originally wrote) copies the contents of the file to a list and iterates over that. Using</p> <pre><code>while (my $line = &lt;$filehandle&gt;) { ... } </code></pre> <p>does not. When dealing with small files the difference isn't significant, but when dealing with large files it definitely can be.</p> <hr> <p>Answering the (updated) question ("Does Perl have an equivalent to PHP's <code>readfile()</code> function ... ?"), the answer is <a href="http://search.cpan.org/dist/Perl6-Slurp/Slurp.pm#DESCRIPTION" rel="nofollow noreferrer">slurping</a>. There are a <a href="http://www.perl.com/pub/a/2003/11/21/slurp.html" rel="nofollow noreferrer">couple of syntaxes</a>, but <code>Perl6::Slurp</code> seems to be the current module of choice.</p> <p>The implied question ("why doesn't the browser prompt for download before grabbing the entire file?") has absolutely nothing to do with how you're reading in the file, and everything to do with what the browser thinks is good form. I would guess that the browser sees the mime-type and decides it knows how to display plain text.</p> <hr> <p>Looking more closely at the Content-Disposition problem, I remember having similar trouble with IE ignoring Content-Disposition. Unfortunately I can't remember the workaround. <a href="http://www.hanselman.com/blog/TheContentDispositionSagaControllingTheSuggestedFileNameInTheBrowsersSaveAsDialog.aspx" rel="nofollow noreferrer">IE has a long history of problems here</a> (old page, refers to IE 5.0, 5.5 and 6.0). For clarification, however, I would like to know:</p> <ol> <li><p>What kind of link are you using to point to this big file (i.e., are you using a normal <code>a href="perl_script.cgi?filename.txt</code> link or are you using Javascript of some kind)?</p></li> <li><p>What system are you using to actually serve the file? For instance, does the webserver make its own connection to the other computer without a webserver, and then copy the file to the webserver and then send the file to the end user, or does the user make the connection directly to the computer without a webserver?</p></li> <li><p>In the original question you wrote "this does not cause the browser to prompt for download before grabbing the entire file" and in a comment you wrote "I still don't get a download prompt for the file until the whole thing is downloaded." Does this mean that the file gets displayed in the browser (since it's just text), that after the browser has downloaded the entire file you get a "where do you want to save this file" prompt, or something else?</p></li> </ol> <p>I have a feeling that there is a chance the HTTP headers are getting stripped out at some point or that a Cache-control header is getting added (which apparently can cause trouble).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload