Solved

Adding to strings together in a script

Posted on 1997-11-12
3
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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.

738 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