Skip to content

[doc] perlop: add additional simpler example of using "<<" with "()" #20886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jidanni opened this issue Mar 2, 2023 · 2 comments
Open

[doc] perlop: add additional simpler example of using "<<" with "()" #20886

jidanni opened this issue Mar 2, 2023 · 2 comments

Comments

@jidanni
Copy link
Member

jidanni commented Mar 2, 2023

On perlop there is a rather complex example of using << with ():

   myfunc(<< "THIS", 23, <<'THAT');
Here's a line
or two.
THIS
and here's another.
THAT

There perhaps ought to be a an additional simpler example first,

print uc(<<EOF);
abc
EOF

Except I don't know where on that page to put it.

Perhaps someone could put something like that somewhere on that page. Thanks.

@rwp0
Copy link
Contributor

rwp0 commented Mar 2, 2023

I always do:

my $person = 'John';

print uc <<~ "TEXT"; # add space around, quote the token, might always use ~
  Hello, $person!  
  And the text goes on.
  TEXT

Which results in:

HELLO, JOHN!  
AND THE TEXT GOES ON.

Not sure if bareword token is recommended.

Wish ~ were always there, added by default (for indentation = readability).


NB. EOF (end of file) in the example could be replaced ith EOT (end of text) for clarity

And that "THIS" could include a $variable within the heredoc (to use its surrounding double quotes for a purpose)

@jidanni
Copy link
Member Author

jidanni commented Mar 3, 2023

Well all that is great to mention too.
All I know is a user is trying to lookup how to stuff a <<EOF into ( ) in a hurry.

khwilliamson added a commit to khwilliamson/perl5 that referenced this issue May 4, 2025
khwilliamson added a commit to khwilliamson/perl5 that referenced this issue May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants