Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

Could any body please guide me how to concatenate the value of two variable?

I have Googled for it and found lots ways but whenever I tried to concatenate I got failed.

I have tried the following lines:
JavaScript
print "Enter the name";
$baseStream = <> ;
$b = 1;
$strName = "${$baseStream}_Strm_${b}";
print $strName;

If I entered the name XYZ then expected output is : XYZ_Strm_1

But in command line I am getting output as :
XYZ
_Strm_1

I just don't understand why the output is got split in two lines.

Please help me.

Thanks in advance.

-Nilesh
Posted
Updated 22-Dec-11 22:03pm
v2

Your $baseStream variable is including the newline character(s). Try this:

PERL
print "Enter the name";
$baseStream = <> ;
chomp $baseStream;
$b = 1;
$strName = "${baseStream}_Strm_${b}";
print $strName;


"chomp" is a function that removes the line separator from the end of a string.
I've removed the extra $ symbol from inside "{}" too.
 
Share this answer
 
Comments
nilesh.d.mankar 16-Jan-12 4:42am    
thanks, it works.
nilesh.d.mankar 16-Jan-12 4:47am    
1 more question how to store command prompt output into any veriable in perl??
do you have any idea?

I have a some commands and I need to fetch their output into any veriable,
smetimes these commands give the output as a single values or sometimes in multivalue.
I wan to store them into array veriable.
How can I do it??
Hi,
Remove the chomp and use concatenation operator(.).
 
Share this answer
 
Comments
nilesh.d.mankar 16-Jan-12 4:42am    
thanks to u also... its also working
nilesh.d.mankar 16-Jan-12 4:47am    
1 more question how to store command prompt output into any veriable in perl??
do you have any idea?

I have a some commands and I need to fetch their output into any veriable,
smetimes these commands give the output as a single values or sometimes in multivalue.
I wan to store them into array veriable.
How can I do it??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900