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';
| [reply] |
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. | [reply] |
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:??; | [reply] |
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
| [reply] [d/l] [select] |
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';
| [reply] [d/l] [select] |
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
| [reply] |
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
| [reply] [d/l] |