Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

heredoc within a delimited construct

by BeneSphinx (Acolyte)
on Feb 19, 2013 at 00:02 UTC ( #1019418=perlquestion: print w/ replies, xml ) Need Help??
BeneSphinx has asked for the wisdom of the Perl Monks concerning the following question:

I was reading the Perl docs on heredoc just now, and found one description that I found very confusing. I'm hoping you can help me understand what's being described here: http://perldoc.perl.org/perlop.html#Quote-Like-Operators

Specifically, this part:

If you use a here-doc within a delimited construct, such as in s///eg, the quoted material must come on the lines following the final delimiter. So instead of

s/this/<<E . 'that' the other E . 'more '/eg;
you have to write
s/this/<<E . 'that' . 'more '/eg; the other E

I understand the part about placing the heredoc after the s// construct, but the substitution itself is confusing. Does it mean the same as this?

s/this/the other\nthatmore /eg;
I guess I'm wrong to assume those periods are concatenation operators, but if so, what's going on here? What's the use case?

Thanks very much in advance!

Comment on heredoc within a delimited construct
Select or Download Code
Replies are listed 'Best First'.
Re: heredoc within a delimited construct
by jwkrahn (Monsignor) on Feb 19, 2013 at 03:42 UTC

    Does it mean the same as this?

    s/this/the other\nthatmore /eg;

    No, it is the same as this:

    s/this/the other\nthatmore /g;

    The /e option is only needed for the concatenation operator to work.

Re: heredoc within a delimited construct
by LanX (Canon) on Feb 19, 2013 at 00:26 UTC
    here-docs ALWAYS start in the line after the first (statement delimiting) semicolon.

    > I guess I'm wrong to assume those periods are concatenation operators, but if so, what's going on here?

    You're not wrong it's a concat. e evals the replacement part before inclusion!

    Check the regex docs for details.

    > Does it mean the same as this? ...

    I think so. I didn't try, but why didn't you?

    Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019418]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-30 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls