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

Hi,

Is there any module that help us to simplify verbatim text formatting as below?
my $var1 = "foo"; my $here_is = <<SOME_TEXT; I want to print something with a value $var1 and some other text load etc etc SOME_TEXT print $here_is; print "\n";

Regards,
Edward

Replies are listed 'Best First'.
Re: Module for Perl's "here-is" text formatting
by marto (Cardinal) on May 24, 2006 at 10:11 UTC
Re: Module for Perl's "here-is" text formatting
by blazar (Canon) on May 24, 2006 at 10:19 UTC

    As others wrote, you should explain what you mean with "simplify". Since you mentioned "verbatim text" I suspect you may just want to avoid interpolation. In this case just use

    my $here_is = <<'SOME_TEXT';

    or else, please just explain!

Re: Module for Perl's "here-is" text formatting
by Mutant (Priest) on May 24, 2006 at 10:12 UTC
    Not exactly sure what you mean by "simplify". What you have is pretty simple.

    If you want to remove the text / formatting from your code, then you might want to look at one of the many templating modules. Template is probably a good start, or HTML::Template if it's HTML based.
Re: Module for Perl's "here-is" text formatting
by TedPride (Priest) on May 24, 2006 at 17:04 UTC
    What you're probably looking for is a way to load data into your template from variables. But you're going about this the wrong way. Use a hash to store the data, and regex to substitute:
    use strict; use warnings; my %vars = ( var1 => 'MyValue', ); my $here_is = <<SOME_TEXT; I want to print something with a value %var1% and some other text load etc etc SOME_TEXT $here_is =~ s/%(\w+?)%/$vars{$1}/g; print $here_is;
    You may also want to look at loading the template from a file or __DATA__, so you're not forced to allow the extra line break that <<TAG makes mandatory.