Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding to strings together in a script

Posted on 1997-11-12
3
Medium Priority
?
168 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 200 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 85

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

916 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