Solved

Adding to strings together in a script

Posted on 1997-11-12
3
148 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now