×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help! How do I add two strings together?

Help! How do I add two strings together?

Help! How do I add two strings together?

(OP)
My problem isn't that simple though...
One of those strings is in a array.

For example, the following program:
@test = ('bob', 'sid', 'derek');
foreach $test (@test) {
    $test = $test + "n";
    print $test;}

produces:
000

not bobnsidnderekn like I would suspect.
How do I add a scalar/string to a scalar/string in array.

Chris

RE: Help! How do I add two strings together?

$test corresponds to the individual array item, so you can't exactly just go performing commands on it. Best to use a different variable like this:

foreach $test (@test) {
  $testPrint = $test + "n";
  print $testPrint;
}

Or for this example alone, just do this:

print $test + "n";

Best of luck!

Liam Morley
lmorley@wpi.edu
] :: imotic :: website :: [
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."

RE: Help! How do I add two strings together?

Additionally,
the '+' is an arithmatic operator.  When you add alphas you get zero.

If you want to concatentate your elements you need to use '.' or 'join'.

A simple example......
#!/usr/local/bin/perl
@test = ('bob','sue','joe','ann');
$added = $test[0] + "n";
print "Added -> $added\n"; # prints 0
$firstTwo = $test[0].$test[1];
print "$firstTwo\n";# prints bobsue


Hope this helps...




keep the rudder amid ship and beware the odd typo

RE: Help! How do I add two strings together?

I'm not sure what it means to concatentate something.......
I probably meant 'concatenate'  ;^)




keep the rudder amid ship and beware the odd typo

RE: Help! How do I add two strings together?

thanks, goBoating- I've been working with Java too long, I've almost forgotten these things :o)

Liam Morley
lmorley@wpi.edu
] :: imotic :: website :: [
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."

RE: Help! How do I add two strings together?

(OP)
Man,

You guys Rock!
Thanks for correcting me!

HuckFinn

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close