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

Hi Perl Monks,

Recently i came across code which looks like this

my $code = << 'ET'; { --- Some lines of code --- } ET test($code);

From what i can make out is the variable $code holds the code snippet terminating at ET. Am i correct ?

What is the use case/advantage of this implementation ?

Thanks in advance.

Replies are listed 'Best First'.
Re: Assigning Perl code snippet to a variable
by ungalnanban (Pilgrim) on Mar 02, 2010 at 06:27 UTC

    The Advantages of the here string is we can write a set of instruction or a function with in this here string. then we can give this to eval.

    here-doc/here-string allows us to print multi-line without worrying about the quotes and escaping that come with the standard method of the defining string.


    --sugumar--
Re: Assigning Perl code snippet to a variable
by Anonymous Monk on Mar 02, 2010 at 08:59 UTC
    See perlop, and remember to tell your teacher you asked here