Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating 2 array variables

Status
Not open for further replies.

BoilerZ

Programmer
Sep 25, 2003
3
US
I'm trying to concatenate two array variables of type string. I'm using this inside of a sub and for some reason it's not working.

$Config{'sender'} = "$Config{'sender'}\@$Config{'sender_domain'}";

This works, but the previous doesn't. Any ideas?
print MAIL "$Config{'sender'}\@$Config{'sender_domain'}\n";

 
Try the following:


$Config{sender} = $Config{sender}."@".$Config{sender_domain}."\n";

I tend to keep variables out of strings for clarity anyway.

Scotty
 
sdeakin - I've tried every variant of that. It's quite frustrating. I'm able to assign strings into the array:

$Config{'sender'} = "someone\@somewhere.com";

So I know that I'm able to change the variable, but it's not allowing me to assign it to anything else ... extreme bloat example

$tmpVar1 = $Config{'sender'};
$tmpVar2 = $Config['sender_domain'};
$tmpVar3 = $tmpVar1"\@"$tmpVar2;
$Config{'sender'} = $tmpVar3;

Yes I even tried that.
 
Hi B,

That is very bizzare.... if I run the following script:

#!/usr/bin/perl -w
use strict;

my %Config;

$Config{sender} = "jimbob";
$Config{sender_domain} = "funny.money.com";

$Config{sender} = $Config{sender}."\@".$Config{sender_domain};

print $Config{sender}."\n";

---------------
I get the following output:

[scott@holly tek-tips]$ ./concat.pl
jimbob@funny.money.com

So the assignment is okay. What version of perl are you using and what OS? I am running 5.8.0 on linux.

Scotty


 
That's the thing, I'm not sure what version of Perl I'm using. It's on a SUN Cobalt server somewhere in NY. I know that it should work, but it isn't. I know the code should work. Any other ideas?
 
Do a perl -V for the version and build info

Run perl manually under the debugger and make assignments and see what happens i.e:

[scott@holly wsqm]$ perl -d -e 0

Loading DB routines from perl5db.pl version 1.19
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(-e:1): 0
DB<1> $Config{sender} = &quot;jimbob&quot;;

DB<2> x $Config
0 undef
DB<3> x %Config
0 'sender'
1 'jimbob'
DB<4> $Config{sender_domain} = &quot;funny.money.com&quot;;

DB<5> x %Config
0 'sender_domain'
1 'funny.money.com'
2 'sender'
3 'jimbob'
DB<6> $Config{sender} = $Config{sender}.&quot;\@&quot;.$Config{sender_domain};

DB<7> x %Config
0 'sender_domain'
1 'funny.money.com'
2 'sender'
3 'jimbob@funny.money.com'


This way you can see what %Config is set to after each assignment.

Scotty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top