git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: Show project README if available

From
Jeff King <peff@peff.net>
Date
Oct 11, 2006, 18:17 UTC
Message-ID
<20061011181729.GB2897@coredump.intra.peff.net>
In-Reply-To
<200610111423.00656.jnareb@gmail.com>
On Wed, Oct 11, 2006 at 02:23:00PM +0200, Jakub Narebski wrote:
> Can any Perl expert tell us how Perl truly solve this? What is the best
> way to dump whole [remaining] contents of file (from filehandle) to STDOUT?

The same you would in C: read fix-sized buffers and dump them. Reading the whole file obviously has unbounded memory allocation. Reading lines requires unnecessary parsing and may have unbounded memory allocation (though in practice for text files I doubt either is a big deal).

You can loop like this:
while(1) {
  my $r = read(STDIN, my $buf, 4096);
  defined($r) or die "error: $!";
  $r or last;
  print STDOUT $buf;
}
Or you can use the File::Copy module, which is part of the standard
distribution (and I believe has been so for all perl5 versions, but I
could be wrong):
  use File::Copy qw(copy);
  copy(STDIN, STDOUT);
-Peff
Previous: Jakub NarebskiNext: Jakub Narebski
Message 11 of 14 in “gitweb: Show project README if available”
  1. gitweb: Show project README if availablePetr Baudis, Oct 10, 2006
  2. Junio C HamanoOct 10, 2006
  3. Junio C HamanoOct 10, 2006
  4. Petr BaudisOct 10, 2006
  5. Jakub NarebskiOct 10, 2006
  6. Luben TuikovOct 10, 2006
  7. Andreas EricssonOct 10, 2006
  8. Jakub NarebskiOct 10, 2006
  9. Petr BaudisOct 10, 2006
  10. Jakub NarebskiOct 11, 2006
  11. Jeff KingOct 11, 2006
  12. Jakub NarebskiOct 11, 2006
  13. Junio C HamanoOct 11, 2006
  14. Jakub NarebskiOct 11, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.