Well, I thought this might be useful to some, just a boring post to others, but I decided to go ahead and post this anyways. (hopefully the right place was choosen to post).

Alright, you have your normal ways of connecting like:

$string .= "something";

or:

$string = "something" . "more";

but the way I prefer is like this:

open(THIS, "${file}/${user}.txt");

just put $ then an opening bracket, the variable name, then the closing bracket, then whatever you want around it. You can play around with it to test it out, but this is the way I have always prefered. Hope this helps at least one person.

Replies are listed 'Best First'.
Re: An easier way for connecting strings.
by sauoq (Abbot) on Sep 17, 2002 at 23:57 UTC

    And you don't even need the braces most of the time! For instance, "$file/$user.txt" works fine. The braces are required when you need to specify exactly what the variable name is because the next character could be interpreted as part of the name. For example, "$file_640x480.jpg" might need to be written as "${file}_640x480.jpg" unless you have a variable called $file_640x480.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: An easier way for connecting strings.
by grantm (Parson) on Sep 17, 2002 at 23:52 UTC

    Yes, 'interpolation' as it is known is one of the features of Perl (probably stolen from the Unix shell) that other languages are most jealous of. I never enjoy the concatentation process in say JavaScript and don't even get me started on Java :-)

    By the way, you only need to use the braces round the variable name when its followed by valid name characters, eg: you can simply say something like "$dir/$user.txt" (although a more portable approach would be to use File::Spec).