in reply to Printing an array in a Here Doc

my @array = qw( what happened when you tried it? ); print <<EOT; @array EOT

It works fine; you may just want newlines not spaces between elements (in which case see the documentation for $" in perlvar).

Replies are listed 'Best First'.
Re^2: Printing an array in a Here Doc
by tmtech1 (Initiate) on Jun 27, 2006 at 20:29 UTC
    I do need newlines. But, I couldn't figure out the exact place to put the loop. Could I put it inside of the here doc?
      No. Whatsoever control statements are not evaluated in a here-doc. The here-doc is essentially a string, and if you place an array inside it, it is interpolated into the string. Yes, there is looping over the array elements going on behind the scenes, and in this loop the array elements are joined with the contents of the variable $" as glue.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}