In Perl most of my print
statements take the form
print "hello." . "\n";
Is there a nice way to avoid keeping all the pesky "\n"s lying around?
I know I could make a new function such as myprint
that automatically appends \n, but it would be nice if I could override the existing print
.
Perl 6 has the say
function that automatically appends \n
.
You can also use say
in Perl 5.10 or 5.12 if you add
use feature qw(say);
to the beginning of your program. Or you can use Modern::Perl to get this and other features.
See perldoc feature for more details.
You can use the -l
option in the she-bang header:
#!/usr/bin/perl -l $text = "hello"; print $text; print $text;
Output:
hello hello
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With