For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2004 > Inserting variable within <<EOL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Inserting variable within <<EOL
Winston Kotzan

2004-05-23, 4:36 pm

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.


--
Winston Kotzan
http://www.wakproductions.com/



Gunnar Hjalmarsson

2004-05-23, 5:34 pm

Winston Kotzan wrote:
> 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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Hynek Schlawack

2004-05-23, 5:34 pm

* "Winston Kotzan" <redalert@wakproductions.com> wrote:

> 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.


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

> Help is greatly appreciated. Thanks.


HTH
Winston Kotzan

2004-05-23, 11:31 pm

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


--
Winston Kotzan
http://www.wakproductions.com/


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2hcertFalt3gU1@uni-berlin.de...
> Winston Kotzan wrote:
>
> ${myvar}thing
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>



Uri Guttman

2004-05-24, 1:32 am

>>>>> "WK" == Winston Kotzan <redalert@wakproductions.com> writes:

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

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Web Surfer

2004-05-24, 3:31 pm

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

In article <p97sc.11$uc.4@newssvr19.news.prodigy.com>,
redalert@wakproductions.com says...
> 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.


> 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.
>
>
> --
> Winston Kotzan
> http://www.wakproductions.com/
>
>
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com