Kapusta
asked on
Adding to strings together in a script
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Unquoted string "there" may clash with future reserved word at thewitt line 3.
#And to complete the list:
$hi = join("",$firstvar,$secondv ar);
$hi = pack("a*a*",$firstvar,$sec ondvar);
($hi = $firstvar).=$secondvar;
substr($hi=$secondvar,0,0) =$firstvar ;
($hi = $firstvar)=~s/$/$secondvar /;
#hmm, any more?
#And to complete the list:
$hi = join("",$firstvar,$secondv
$hi = pack("a*a*",$firstvar,$sec
($hi = $firstvar).=$secondvar;
substr($hi=$secondvar,0,0)
($hi = $firstvar)=~s/$/$secondvar
#hmm, any more?
$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