Example 2-7. examples/scalars/string_operators.p6
#!/usr/bin/perl6 my $x = "Hello"; my $y = "World"; # ~ is the concatenation operator, ataching ons string after the other my $z = $x ~ " " ~ $y; # the same as "$x $y" say $z; # Hello World my $w = "Take " ~ (2 + 3); # you cannot write "Take (2 + 3)" here say $w; # Take 5 $z ~= "! "; # the same as $z = $z ~ "! "; say "'$z'"; # 'Hello World ' # x is the string repetition operator my $q = $z x 3; print "'$q'\n"; # 'Hello World! Hello World! Hello World! '
~ concatenates two strings.
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Division | Up | if statement - comparing values |