Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day loris, The reason you're getting that error is because the heredoc (in your module) is being interpolated. In your module, you've probably either coded <<"PROLOG" or <<PROLOG. See perlop: Quote-Like Operators for an explanation of how explicit single- and double-quoted terminating strings (i.e. PROLOG in your example) are interpolated; also note that the absence of explicit quotes assumes double-quotes. There are a variety of hoops you have to jump through to get similar code working in a one-liner. These have mostly been pointed out in various replies. You could embed newlines in your one-liner and do something like this:
That's not using the module as such; just running the code in a package other than main. You're also using a different (albeit equivalent) method of quoting the terminator (i.e. <<\TEST). What you'd really want is something closer to this:
That's a lot of effort; it's not really comparing apples with apples; and, given you could have copied most of the code you already had, probably takes a similar amount of time as coding this test script:
and this test module:
Running that script produces:
Changing <<'PROLOG' to either <<"PROLOG" or <<PROLOG, produces (in both cases):
You now have a valid test which reproduces what you were attempting to test and, I suspect, would have taken less time than writing and posting your OP. -- Ken In reply to Re: Heredoc in one-liner?
by kcott
|
|