-2

I am trying to read input of two strings from the user keyboard, store them in two variables and concatenate the two strings together using the Perls dot operator.

Research I found online shows an example similar to what I am trying to accomplish. This example uses only one string variable in the concatenation but I think something similar should be able to concatenate multiple variables together:

$name = checkbook'; 
$filename = '/tmp/' . $name . '.tmp'; 

#$filename now contains "/tmp/checkbook.tmp"

(http://alvinalexander.com/perl/edu/articles/pl010003.shtml)

my code is displayed in the following - however, I am still getting the undesired concatenation :

$stringa=<STDIN>;
$stringb=<STDIN>;
print $stringa.$stringb;

compiled using perl (path)

output

     nein
     ja
     nein
     ja

instead of the desired output:

 nein
 ja
 neinja

why am I not getting the concatenation output I think it should produce?

Cœur
  • 37,241
  • 25
  • 195
  • 267
T.Over
  • 1
  • 1

1 Answers1

1

You can use "chomp" to remove the trailing string "\n", like this:

$stringa=<STDIN>;
$stringb=<STDIN>;
chomp($stringa);
chomp($stringb);
print $stringa.$stringb;
asthman
  • 145
  • 1
  • 6