Reputation: 1346
Rather than summing the result in one line and printing it in another line? If I have this data
my $a = 1;
my $b = 2;
Currently, if I want to print the sum result, I need to write the code like this
my $tmp = $a+$b;
print "result=$tmp\n";
Is there to the same as above by something looking similar to
print "result=$a+$b\n";
Upvotes: 3
Views: 177
Reputation: 385546
print "Result=", $a+$b, "\n"; # Multi-arg print
print "Result=".($a+$b)."\n"; # Concatenation
print "Result=${\( $a+$b )}\n"; # ref-deref trick (scalar context)
print "Result=@{[ $a+$b ]}\n"; # ref-deref trick (list context)
printf "Result=%s\n", $a+$b; # printf
print sprintf("Result=%s\n", $a+$b); # sprintf
Upvotes: 4