in reply to RE: Something is wrong and I don'tkow what
in thread Something is wrong and I don'tkow what

And now for another episode of HereDoc theater...

Look at this for a second and see if you get it, eventually you will want to look at perldoc perlop and search down to Regexp Quote-Like Operators or look in the Camel 2ed at page 43 "Here Docs" (I've never found here-documents in perldoc, anyone??? ahh perldoc perldata, thanks tilly!)

print <<BODY; Content-type: text/html <html><head><title>Nocc Call Log</title></head> <body bgcolor="#FFFFFF"> <h1>Nocc Call Log</h1> <table border="4"> <form action="post.cgi" method="POST"> <tr> <td> <h3>Callers Name: <input type="text" name="caller" size="25"></h3> </td> <td bgcolor="#FFDEAD"> <h3>Auto Time : <input TYPE="radio" NAME="time-Type" VALUE="auto_ +time"></h3> <br> <h3>Manual Time : <input TYPE="radio" NAME="time-Type" VALUE="manua +l_time"></h3> </td> <td bgcolor="#FFDEAD"> <h3>Time: <input type=\"text\" name=\"time\"></h3>\n"; </td>\n"; </tr>\n"; BODY # BODY is the end of the heredoc, and CANNOT have space # before or after it unless you get fancy # and do the print above as: # print <<" FANCY WITH Spaces in FRONT"; # and then you would end it with the following, minus the "#": # FANCY WITH Spaces in FRONT

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

Replies are listed 'Best First'.
RE: RE: RE: Something is wrong and I don'tkow what
by Caillte (Friar) on Oct 18, 2000 at 14:43 UTC
    Something people tend to forget. It's not really a good idea to use:

    print <<BLOCK_END;

    Why? It's a bareword!

    Barewords aren't really defined in the language and can be subject to change. However:

    print <<"BLOCK_END"; will always expand variables while:

    print <<'BLOCK_END'; will perform no parsing of the text.

      In this case it most definitely is not a problem, indeed in the examples of "here-doc" syntax in perldata the first example uses a bare-word.

      While it may confuse people, the following does not confuse Perl:

      print <<print; Just another Perl hacker, print
      As tilly points out, perl has no problem with it. I tend to guide people towards the quoted version simply for a stylistic reason: not only does it look better (IMO) but it makes it easier to catch mistakes like:
      print << RAGNAROCK Thor Odin RAGNAROCK
      Technically, it isn't a bareword, AFAIK. -w doesn't complain about it, nor does use strict. It isn't a bareword, it's part of an operative phrase. You can even use perlfunc words and symbols there, try out:
      #!/usr/bin/perl -w use strict; print <<print; print me print (my $s = <<s) =~s/\//\/\//s; s\/\/\/\/s s print "$s";

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