Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
more useful options
 
PerlMonks  

juxtapose

by Keef (Sexton)
on Mar 31, 2001 at 00:57 UTC ( [id://68594]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Keef has asked for the wisdom of the Perl Monks concerning the following question:

I have a two variables, how do I justapose them so they create a 3rd variable. Like so:
$var1 = "cream"; $var2 = "coffee"; $var3 = $var2 " & " $var1; print $var3 # returns "coffee & cream"

Replies are listed 'Best First'.
Re: juxtapose
by dws (Chancellor) on Mar 31, 2001 at 01:02 UTC
    The string concatenation operator is .

    Applying this operator is left as an exercise.

Re: juxtapose
by greenFox (Vicar) on Mar 31, 2001 at 01:05 UTC
    I'm not sure I understand what you mean by juxtapose but this works for me-
    $var1 = "cream"; $var2 = "coffee"; $var3 = $var2 . " & " . $var1; print $var3 # prints "coffee & cream"
    which uses the '.' operator to concatenate the strings, is that what you wanted?

    --
    my $chainsaw = 'Perl';

Re: juxtapose
by MeowChow (Vicar) on Mar 31, 2001 at 01:38 UTC
    To quote the Beasty Boys, "I like my sugar with coffee & cream". Moving on...
    $var3 = "$var1 & $var2"; $var3 = $var1 . " & " . $var2; $var3 = join ' & ',$var1,$var2; undef $var3; $var3 .= $_ for $var1 =~ /./sg,' ','&',' ',split//,$var2;
    The choice of WTDI is up to you =)
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re (tilly) 1: juxtapose
by tilly (Archbishop) on Mar 31, 2001 at 18:53 UTC
    The usual answer is to use interpolation.
    print "$var2 & $var1"; # Prints "coffee & cream"
    That is why all of those funny little symbols are used, to make it easy to drop variables directly in strings...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://68594]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.