Inserting variable within <<EOL

W

Winston Kotzan

Hello,

I am having a perplexing problem inserting a variable in the middle of text
without a space. For example:


$myvar = 'some';
print <<STOP
I want $myvar thing between text.
STOP

This would output:
I want some thing between text.

The difficulty arises when I want to insert $myvar without a space between
the words; I want the output to look like this:
I want something between text.

What can I do to join $myvar and the following 'thing' as one word in the
above string construct?

Help is greatly appreciated. Thanks.
 
G

Gunnar Hjalmarsson

Winston said:
I am having a perplexing problem inserting a variable in the middle
of text without a space. For example:

$myvar = 'some';
print <<STOP
I want $myvar thing between text.
STOP

This would output:
I want some thing between text.

The difficulty arises when I want to insert $myvar without a space
between the words; I want the output to look like this:
I want something between text.

What can I do to join $myvar and the following 'thing' as one word
in the above string construct?

${myvar}thing
 
U

Uri Guttman

WK> Thanks to everyone who responded. I can't believe the answer was
WK> so simple!

please don't top post. read the group guidelines (posted regularly)

and note that the answer is the general way to interpolate a variable
when it is followed by a valid token string. the fact that you were
using a here doc make no difference as it works in any doublequotish
string.

<snip of full quote>

uri
 
W

Web Surfer

[This followup was posted to comp.lang.perl.misc]

Hello,

I am having a perplexing problem inserting a variable in the middle of text
without a space. For example:


$myvar = 'some';
print <<STOP
I want $myvar thing between text.

I want ${myvar}thing between text.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top