in reply to You can do string interpolation on sub output
in thread What's the Right Way to declare constants in packages?
When run, prints:sub pi { 'apple 3.1415936535897532'; } my $str = "I like breadnbutter. I like toasted ham. I like @{[pi]}"; print $str, $/;
notI like breadnbutter. I like toasted ham. I like apple 3.14159365358975 +32
Which is what your post said. But I think that's what you meant, so its ok. My real problem is that you are jumping through several hoops to do something that is trivial with a scalar:I like bread and butter. I like toast and jam. I like pi
sub pi { 'apple 3.1415936535897532'; } my $Nov_Pi = 'pumpkin pie'; # Make anonymous array ref with output of pi(). Then de-ref the array. my $str = "I like breadnbutter. I like toasted ham. I like @{[pi]}"; # Concatenate a scalar. my $Nov_str = "I also like $Nov_Pi"; print $str, $/, $Nov_str, $/;
|
|---|