Solved

Adding to strings together in a script

Posted on 1997-11-12
3
159 Views
Last Modified: 2013-12-25
It would be helpful to learn how to add two string variables together in a script.

Example:

$firstvar = "Hello "
$secondvar = "world"

How do you make a new variable with "Hello world" using $firstvar and $secondvar

In GWBASIC I can simply do this:

Hi$ = Firstvar$ + SecondVar$

How does one do this in Perl?
0
Comment
Question by:Kapusta
3 Comments
 
LVL 1

Accepted Solution

by:
twexperts earned 50 total points
ID: 1831162
Hello again,
all you need to do for this is:
$Hi = "$FirstVar $SecondVar";

Robin (twexperts)
0
 

Expert Comment

by:thewitt
ID: 1831163
Actually, the concatenation operator in perl is a ., however joining two strings by using variable expansion inside quotes is the more common method.

$hello = "hello ";
$there = "there";
$hi = $hello . there;

You can see why this would not be the simpliest method since you need to leave blank spaces if you want your $hi string to be "hello there" and not "hellothere."

Tim
0
 
LVL 84

Expert Comment

by:ozo
ID: 1831164
Unquoted string "there" may clash with future reserved word at thewitt line 3.

#And to complete the list:
$hi = join("",$firstvar,$secondvar);
$hi = pack("a*a*",$firstvar,$secondvar);
($hi = $firstvar).=$secondvar;
substr($hi=$secondvar,0,0)=$firstvar;
($hi = $firstvar)=~s/$/$secondvar/;
#hmm, any more?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question