Including images (or any type of data in the __DATA__ section. Pretty straightforward, cat the image to the script, change $size appropriatly et voila.

cat image.pl image.jpg >image.pl

The read() stuff is included for easy updating, supposing you want several images in in __DATA__. A plain print <DATA> would've been sufficient ofcourse.
#!/usr/bin/perl $size = 1024; print "Content-type: Image/jpeg\n"; print "Content-length: $size\n\n"; read(DATA,$image,$size); print $image; __DATA__

Replies are listed 'Best First'.
Re: Image __DATA__
by merlyn (Sage) on Mar 15, 2001 at 20:02 UTC
    The proper MIME type is "image/jpeg", case-sensitive. If it works this way, it's because someone is error-correcting, and you'll be burned some day when that same error-correction is not applied.

    -- Randal L. Schwartz, Perl hacker

      NS isnt complaining yet, neither has IE... but indeed mime.types states it as lower cased.

      Thanks for the hint

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
Re: Image __DATA__
by extremely (Priest) on Mar 15, 2001 at 22:04 UTC
    Try cat image.jpg >>image.pl rather than the two file form, unles you are making a new script from the old, ala cat image.pl.base image.jpg > newimage.pl

    --
    $you = new YOU;
    honk() if $you->love(perl)

      Basically any way of getting the data in the __DATA__ block will do. I doubt alot of optimizing can be achieved in this step.

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
        It isn't just optimizing, some shells wind up wiping out the file 'index.pl' and THEN trying to cat the two files together.

        --
        $you = new YOU;
        honk() if $you->love(perl)