Here-document problem

K

KKramsch

The following script works fine:

print <DATA>;
__DATA__
Content-Type: image/png

 PNG
 

IHDR       Çïdm  gAMA ¯È7  é  tEXtSoftware Adobe ImageReadyqÉe< 6PLTEeeeêêêyyyooo   ppp   ÌÌÌõõõËËËááá···ÖÖÖ­­­   ÿÿÿ[[[ÿÿÿ cA   tRNSÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ â¿¿   IDATxÚb D   Ä ÈÁÆ  ì    Ä È+        *ÂÌÈÏ       L   BÓ       //' 7T    jXøẠ  *     L          /??#  X    "`/@D   Ó=  Ä ÈÅ ä-^AA  bÀ 
    ë  æûuìî IEND®B` 





but this one fails

print <<'EOPNG';
Content-Type: image/png

 PNG
 

IHDR       Çïdm  gAMA ¯È7  é  tEXtSoftware Adobe ImageReadyqÉe< 6PLTEeeeêêêyyyooo   ppp   ÌÌÌõõõËËËááá···ÖÖÖ­­­   ÿÿÿ[[[ÿÿÿ cA   tRNSÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ â¿¿   IDATxÚb D   Ä ÈÁÆ  ì    Ä È+        *ÂÌÈÏ       L   BÓ       //' 7T    jXøẠ  *     L          /??#  X    "`/@D   Ó=  Ä ÈÅ ä-^AA  bÀ 
    ë  æûuìî IEND®B` 
EOPNG

with the error message "Can't find string terminator EOPNG anywhere
before EOF". Is there anyway to get the here-document version of
this script to work?

Thanks!

Karl
 
G

Gunnar Hjalmarsson

KKramsch said:
... "Can't find string terminator EOPNG anywhere before EOF". Is
there anyway to get the here-document version of this script to
work?

Probably, provided that you comply with the requirements for a
here-document as described in "perldoc perlop" (look for <<EOF).
 
B

Bob Walton

KKramsch wrote:

....

but this one fails

print <<'EOPNG';
Content-Type: image/png

PNG


IHDR Çïdm gAMA ¯È7 é tEXtSoftware Adobe ImageReadyqÉe< 6PLTEeeeêêêyyyooo ppp ÌÌÌõõõËËËááá···ÖÖÖ­­­ ÿÿÿ[[[ÿÿÿ cA tRNSÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ â¿¿ IDATxÚb D Ä ÈÁÆ ì Ä È+ *ÂÌÈÏ L BÓ //' 7T jXøẠ* L  /??# X "`/@D Ó= Ä ÈÅ ä-^AA bÀ
ë æûuìî IEND®B`
EOPNG

with the error message "Can't find string terminator EOPNG anywhere
before EOF". Is there anyway to get the here-document version of
this script to work?


Well, when I copy/paste your code verbatim, it seems to work fine
(prints out the gibberish, anyway). Could you post code which actually
exhibits the problem you are having?


....
 
J

Jeff 'japhy' Pinyan

but this one fails

print <<'EOPNG'; [...]
EOPNG

with the error message "Can't find string terminator EOPNG anywhere
before EOF". Is there anyway to get the here-document version of
this script to work?

Is it possible you *don't* have a newline at the end of your file? That
is, does your file end after the "EOPNG", or on a line below it? Believe
it or not, not having a trailing newline causes the error you're
receiving, and if you're on Windows, you're probably using a text
editor that doesn't give you an automatic newline.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
RPI Corporation Secretary % have long ago been overpaid?
http://japhy.perlmonk.org/ %
http://www.perlmonks.org/ % -- Meister Eckhart
 
B

Ben Morrow

Quoth KKramsch said:
The following script works fine:

print <DATA>;
__DATA__
Content-Type: image/png
but this one fails

print <<'EOPNG';
Content-Type: image/png
EOPNG

with the error message "Can't find string terminator EOPNG anywhere
before EOF". Is there anyway to get the here-document version of
this script to work?

I'm not entirely sure why it isn't working (maybe you've not got a
newline before EOPNG?) but anyway you shouldn't put binary data straight
into perl source. I would suggest Base64-encoding it and using
MIME::Base64; or, better, use a separate file.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top