Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add info to $?

Status
Not open for further replies.

jett

Technical User
Sep 13, 2000
22
US
Probably a simple question but I can’t manage to get it work. How do you add something to a “$”.
For example:

$string = “hi, there.”;
$string = $string + “How are you”; (or eval($string)+”how are you”)

doesn’t work to create $string = “hi, there. How are you?”

So, what would be the correct syntax to add contents to the present value of the $?

regards,

jett [sig][/sig]
 
use '.='

$string = 'hi';
$string .= ', there';
print $string; # prints 'hi, there' [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
Thank you goBoating for helping,

$string .='It did work but only partially as <these thingies and everything between it> is ignored!';

with the print result:

It did work but only partially as is ignored!

I tried to put everything between &quot;&quot; like:
$string .='&quot;<something here> and here&quot;';

But didn't work, can this be solved?

Jett
[sig][/sig]
 
hi jett,

its strange that ur <... > r not being printed. send the code..

actually with '' u r asking for no interpretation of special characters... with &quot; &quot; u ask for them to be interpreted.

now <> r not specail characters AFAIK

-shail
[sig][/sig]
 
I'm sorry. What's happening is that everything between <> is not printed BUT it is included in the $ (as seen by schecking the source).

So it is doing what I wanted to. But there is another problem as parts of the contents is formed by individual $'s and it doesn't show the value of the string but the $ itself like:

$string=&quot;fine&quot;;

&quot;How are you? I'm doing $string!&quot;

If I put everyting between &quot;&quot; instead of '' the script doesn't work!

Now I'm stuck on this!

Jett

[sig][/sig]
 
hi jett,

Paste the entire code snippet. If u have just these three lines:
mytest.pl:

my $string=&quot;fine&quot;;
print &quot;How are you? I'm doing $string!&quot;
print 'How are you? I'm doing $string!'

$ perl mytest.pl
How are you? I'm doing fine!
How are you? I'm doing $string!
$
now tell me what is the problem
-shail [sig][/sig]
 
Jett,
are you printing to a browser?
If so, the browser will not know how to interpret non-compliant HTML tags and they will disappear from the browser display. If that is the case, you should be able to view the page source in the browser and see the entire output.

If you are not printing to a browser, try to trim your code down to a few problem lines and post them here. [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
What I'm trying to do is search through a datafile and create some html code when a $ match a field, it does work except from showing the corresponding field which is ouputted as $var. The code looks like this:

if ($var eq $input{'office'}) {
$result .='<option value=&quot;$var&quot;>$var</option>/n';
}

Changing '' into &quot;&quot;, like:

if ($var eq $input{'office'}) {
$result .=&quot;<option value=&quot;$var&quot;>$var</option>/n&quot;;
}

doesn't work (error)!

goBoating, I'm printing to a browser and you're right it does show the complete $ in the source code, it works exactly as I hoped it would except the $var problem. [sig][/sig]
 
Problem is solved, probably not really elegant but this is what I did:

$add='&quot;';
$result .=&quot;<option value=$add$var$add>$var</option>&quot;;

Thanks for all the help,

Jett
[sig][/sig]
 
hi,
does

$result .=&quot;<option value=\&quot;$var\&quot;>$var</option>/n&quot;;

work??

-shail [sig][/sig]
 
I tried, but it still gives errors,

Jett [sig][/sig]
 
Yes it did work Shail, in my first attemp I misstyped it (\&quot;$var&quot;\).

Thank you,

Jett [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top