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

Hello, given the reference $session->param('x') how is it possible to print its content inside an EOF block:
my $html =<<"EOF"; <tag> $session->param('x')</tag> EOF
The above code would result in "CGI::Session=HASH(0x9d56010)->param('x')".
Thank you!

Replies are listed 'Best First'.
Re: OOP: Printing in EOF block
by Eliya (Vicar) on Dec 06, 2011 at 13:56 UTC

    If you want to interpolate it without an extra variable, you can say:

    my $html =<<"EOF"; <tag> @{[ $session->param('x') ]}</tag> EOF

    or

    my $html =<<"EOF"; <tag> ${\$session->param('x')}</tag> EOF

    (The first one implies list context, the latter scalar context.)

      This is what I was searching for. Thank you!
Re: OOP: Printing in EOF block
by choroba (Cardinal) on Dec 06, 2011 at 13:52 UTC
    my $x = $session->param('x'); my $html = <<"EOF"; <tag> $x</tag> EOF
Re: OOP: Printing in EOF block
by AnomalousMonk (Archbishop) on Dec 06, 2011 at 20:29 UTC

    N.B.: The construct you are inquiring about is not an "EOF block", but a Here document.

Re: OOP: Printing in EOF block
by repellent (Priest) on Dec 11, 2011 at 09:54 UTC
    Team totty:
    my $html = sprintf(<<'EOF', $session->param('x')); <tag> %s</tag> EOF