Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

EOF in string

by Anonymous Monk
on Dec 27, 2001 at 16:56 UTC ( [id://134595]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I use Winnperl to run the cript and it says " EOF in string at line13".(which is the second "print<<text"

Please let me know how to do

###here is a part of my script###

open(FILE,">>/home/mombuddy/www/htdocs/sendpic.txt"); print FILE <<text; <p><font face='CordiaUPC'color='#993399'><b> $input{picname}</b></p></ +font> <p>ª×èÍ : $input{name} ÍÒÂØ : $input{age}</p> text print FILE"<p><font color='#0000A0'><strong>Êè§ÀÒ¾Çѹ·Õè : $time[3]/$m +onth[$time[4]]/$ps àÇÅÒ: $time[2].$time[1] ¹.</strong></font></p>\n\ +n\n"; close FILE; print<<text; <body bgcolor="#FFFFFF"> <p>&nbsp;</p> <blockquote> <p><img src="file:///C|/access/flash/mombuddy/index/index_html/image +/baby/baby4.JPG" width="85" height="114"> <font color="#993399"><b><font size="4">ä´éÃѺÃÙ»àÃÕºÃéÍÂáÅéǤèÐ +</font></b></font></p> <blockquote> <p><font size="4" color="#993399"></font></p> </blockquote> </blockquote> </body> </html> text

Replies are listed 'Best First'.
Re: EOF in string
by grinder (Bishop) on Dec 27, 2001 at 17:28 UTC
    The code runs fine on 5.005_03. At first I thought it was a question of the last line not having a terminating newline character but that's not the problem (although there may be a traing space or tab character on the line that could be giving it grief). Apart from the variables that aren't defined, I see no problem with this. Are you sure this fragment as is causes an error on your system, or is there a cut'n'paste problem?

    Minor (major!) style issue, by convention, it is customary to use UPPERCASE heredoc labels. It makes things easier to follow.

    Another issue beside the point is that you are not checking the result of your open call (Hi tilly!). One of these days you will reorganize your web directory tree and this script will quietly start to fail and you won't know why.

    Three questions for you, 1) do you have use strict; at the top of your script and 2) does the first line of the script include the -w switch? What is Winnperl? What does "winnperl -v" produce as output?

    --
    g r i n d e r
    just another bofh

    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u';
Re: EOF in string
by clintp (Curate) on Dec 27, 2001 at 19:37 UTC
    First confirm that the second "text" is indeed flush left in column zero and spelled right. Then a question: is this the whole script? I've found problems with Win32 editors and having here-docs that end on the last line of the script. Apparently Win32 "text files" don't need a trailing newline (as Unix would expect) and this screws up the parser somehow. Put an extra blank line at the end of the script after the end of the here-doc.
Re: EOF in string
by japhy (Canon) on Dec 27, 2001 at 21:07 UTC
    I'm quite sure the problem is that there is no newline at the end of the file. After the last occurrence of "text", a newline is needed.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: EOF in string
by MZSanford (Curate) on Dec 27, 2001 at 17:03 UTC
    i think it looks like the problem is the missing space between print and << .

    Update : I was wrong. Per the below, the space is not needed. I did download and test this, and the code works fine on my Windows machine. (Win98/Cygwin Bash/ActiveState 5.6.1). What kind of machine was this runing on ?
    $ perl -e 'do() || ! do() ;' Undefined subroutine &main::try
      Did you try this out? The << operator does not need to be disambiguated with whitespace, as the following code fragment shows:
      #! /usr/bin/perl -w use strict; print STDOUT<<text; foo bar text

      produces:

      foo bar

      Oops, uploaded the wrong fragment. I tested with an explicit file handle and without. Although for the sake of completeness I guess I should leave both up

      #! /usr/bin/perl -w use strict; print<<text; foo bar text

      --
      g r i n d e r
      just another bofh

      print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u';
Re: EOF in string
by dru145 (Friar) on Dec 27, 2001 at 19:49 UTC

    Using Here documents can cause you alot of grief if you are not careful. They don't seem to have all of the conveniences that were built into Perl (ie. ignoring whitespace). I always found out if I use a Here doc. then I can't put any whitespace before any of the sentence. Everything in the here doc. must be left justified. What has bitten me a few times, is having an extra space at the close of my here doc. I think this is probably your problem. Use a good text editor like vim and it should help you catch these.

    HTP
    -Dru
      Using Here documents can cause you alot of grief if you are not careful.

      You have to know what to expect. HERE docs originated in UNIX shell scripting. The shell, upon detecting a '<<' token, actually seeks ahead in the script file itself until it finds the end token (here, 'text'), and then it writes the intervening lines into a temp file and runs the command line containing with the '<<end_token' construct replaced by simple input redirection from that file.

      This allows including input data in the script itself, rather than requiring separate files, which have the potential for getting out of sync.

      Perl attempts to simulate the same effect, but in an improved way (e.g., the entire HERE doc is treated as though it were surrounded with whatever kind of quotes, if any, surround the end token). Perl does not necessarily use a temp file for each HERE doc, but it helps to think of them as though it did just that. The end token must be the first and only thing on its line or it will be treated as part of the content.

      Within a HERE doc, line endings are treated just like any other character, much the same as if an external file were read using the sequence:

      undef $/; # newlines are not record separators anymore $_ = <>; # slurp the whole file in as one big string

      BTW, it is established convention to use all uppercase characters for the end token.

      dmm

      You can give a man a fish and feed him for a day ...
      Or, you can
      teach him to fish and feed him for a lifetime
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://134595]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-24 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found