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

Hi Perlmonks,

Seek your assistance. I am using here-document to print a POD. The delimiter <<"FOO" is required for interpolation of a few variables (egs. $fnName) . However,there are a few variables which must be printed as its without interpolation (egs. %{$outputParams{PAYLOAD}} , $outputParams{TIMETAKEN}, $outputParams{CMDSTATUS}, $outputParams{CMDOUTPUT}).

The code below gives the obvios error : "Global symbol "%outputParams" requires explicit package name"

I figure that the "print" command can be used as a workaround . Is there any other way to achieve this ?

The codelet is mentioned below :

print <<"FOO"; =head2 $fnName( ) =over 4 =item Parameters: None =item Description: Display backup status. =item Returns: %{$outputParams{PAYLOAD}}; DFM Database related attributes $outputParams{TIMETAKEN}; Time taken to run a CLI at Serve +r $outputParams{CMDSTATUS}; Status returned by the command e +xecuted $outputParams{CMDOUTPUT}; Output returned by the command e +xecuted =back =cut # ================================================================ +=========== FOO

Thanks in advance!

Replies are listed 'Best First'.
Re: Here-document interpolation
by jethro (Monsignor) on Jul 14, 2009 at 10:08 UTC

    The here-doc acts like a normal print statement, so escaping works:

    print <<"FOO"; test \$bla FOO # prints: test $bla
Re: Here-document interpolation
by ropey (Hermit) on Jul 14, 2009 at 10:59 UTC

    You just need to escape it

    E.g.

    print <<"FOO"; =head2 $fnName( ) =over 4 =item Parameters: None =item Description: Display backup status. =item Returns: \%{\$outputParams{PAYLOAD}}; DFM Database related attribut +es $outputParams{TIMETAKEN}; Time taken to run a CLI at Serve +r $outputParams{CMDSTATUS}; Status returned by the command e +xecuted $outputParams{CMDOUTPUT}; Output returned by the command e +xecuted =back =cut # ================================================================ +=========== FOO

    see the

     \%{\$outputParams{PAYLOAD}}
Re: Here-document interpolation
by Anonymous Monk on Jul 14, 2009 at 13:04 UTC

    You could try escaping (as explained above) or you could use multiple here-doc strings, only some of which interpolate:

    print <<"FOO_INTERP" . <<'FOO_NONINTERP'; =head2 $fnName( ) FOO_INTERP =over 4 =item Parameters: None =item Description: Display backup status. =item Returns: %{$outputParams{PAYLOAD}}; DFM Database related attributes $outputParams{TIMETAKEN}; Time taken to run a CLI at Serve +r $outputParams{CMDSTATUS}; Status returned by the command e +xecuted $outputParams{CMDOUTPUT}; Output returned by the command e +xecuted =back =cut # ================================================================ +=========== FOO_NONINTERP

    Or use printf:

    printf <<'FOO', $fname; =head2 %s( ) =over 4 =item Parameters: None =item Description: Display backup status. =item Returns: %{$outputParams{PAYLOAD}}; DFM Database related attributes $outputParams{TIMETAKEN}; Time taken to run a CLI at Serve +r $outputParams{CMDSTATUS}; Status returned by the command e +xecuted $outputParams{CMDOUTPUT}; Output returned by the command e +xecuted =back =cut # ================================================================ +=========== FOO