[sf-perl] Constant in here doc?

David Alban extasia at gmail.com
Thu Jun 9 13:59:03 PDT 2005


Greetings,

How does one use a constant in a here doc?

  use constant FOO => 42;

  my $heredoc <<"EndOfHereDoc";
    FOO
  EndOfHereDoc

  print $heredoc;

I want the constant's value to be printed.  None of the following
resulted in constant FOO's value being printed.  They all printed
literally what you see:

  +FOO
  FOO()
  +FOO()
  &FOO
  &FOO()
  &{ FOO }
  &{ FOO }()
  main::FOO
  +main::FOO
  main::FOO()
  &main::FOO
  &main::FOO()
  +&main::FOO()
  &{ main::FOO }
  &{ main::FOO }()
  +&{ main::FOO }()
  *FOO
  *main::FOO

I know I could assign FOO's value to a variable and then include the
variable in the here doc.  That's probably what I'll end up
(grudgingly) doing.

But darn it to heck!  I want to use a constant, not a variable!

Am I outta luck here?

Thanks,
David
-- 
Live in a world of your own, but always welcome visitors.


More information about the SanFrancisco-pm mailing list