On May 23, 2014, at 2:45 PM, Sherman Willden wrote:
> Disclaimer: I am 67 and not in school. I am doing this for my own
> satisfaction.
>
> How do I get a new line at the end of a non-quoted text. I am doing the
> following:
> Use Math::Trig;
> print pi * 2;
> print "\n";
>
> How do I get the new line on the same line of code?
>
> I could do my $my_pi_times_two = pi * 2;
> print "$my_pi_times_two\n";
>
> but that seems to be overkill.
There are several ways.
1. You can use the new 'say' function, instead of 'print', which automatically
adds a newline to every output. Put 'use feature say' at the beginning of your
program:
say pi * 2;
2. You can print a list:
print pi * 2, "\n";
3. You can concatenate a newline onto the end of your string:
print pi * 2 . "\n";
4. You can use the printf function:
printf "%f\n", pi * 2
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/