Two things:

Firstly, you're probably better off putting the images in separate files. This is mainly for a maintenance reason. Somebody coming along later needing to update your script because one of the images needs to be updated is going to have a hell of a time doing it. If your CGI script is being used in an image context, you're better off having the CGI script open a real .gif file on your local filesystem and just sending the data to the browser.

Secondly, your example of &showgif(1) makes me wonder if you are hoping to be able to use this function multiple times in your CGI script. If so, you can't. Your CGI script can only output a single content type (unless you want to go with some multipart encoding, but I don't know if browsers have enough of a sophisticated support for that sort of thing to be able to interpret it in a way that would make what you're trying to do remotely useful). Any attempts to display multiple GIFs one after the other will fail, because the browser is expecting and assuming the content from that request will be a single item.

You may also wish to take a look at, say, MIME::Base64, which will let you encode/decode binary items in such a way so as to continue to be printable (which seems to be your goal) while being a bit more efficient space-wise than a simple hex string. It'll also take slightly longer to process.


In reply to Re: Embed GIF in perl source? by Fastolfe
in thread Embed GIF in perl source? by epoptai

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.