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

can I use here doc with variables? IE:
$var=<<"EndOfText"; g s d regkngljkasn EndOfText print $var;

Replies are listed 'Best First'.
Re: here doc
by chipmunk (Parson) on Jan 08, 2001 at 09:17 UTC
    To make it explicit: Here-docs are simply strings with a special quoting style. They can be used anywhere you would use a string.

      Well, one thing about them that might catch some by surprise is that a here-doc comes in two pieces and those two pieces can end up pretty far apart. Take an example:

      print <<FOO, <<'BAR'; Usage: $0 [arguments] FOO This program doesn't do much. BAR
      If here-docs were just like strings and didn't come in two parts, then you'd want to write that more like:
      print <<FOO Usage: $0 [arguments] FOO, <<'BAR' This program doesn't do much. BAR;
      which doesn't work. You can write it like this:
      print <<FOO Usage: $0 [arguments] FOO , <<'BAR' This program doesn't do much. BAR ;
      but I think the first example is easier to read.

              - tye (but my friends call me "Tye")
Re: here doc
by $code or die (Deacon) on Jan 08, 2001 at 03:26 UTC
    Yep,

    That worked when you tried it, right?
      no it didnt work. sorry
        Are you sure? I typed "perl" on the command line, pasted your script example in, executed it and it printed what it should have done.

        Could you let us know what happens when you try and run the code?
        A reply falls below the community's threshold of quality. You may see it by logging in.