What is say vs print in Perl?

In Perl, both `print` and `say` are used to output data to the console, but there are key differences between the two:

  • print: This function outputs the given data to the screen but does not automatically append a newline character at the end. You have to manually add a newline if needed.
  • say: This function behaves like `print`, but it automatically appends a newline character to the end of the output, making it easier to print each output on a new line.

Example:

# Using print print "Hello, World!"; # Output without a newline print "Hello, again!\n"; # Output with a newline explicitly # Using say use feature 'say'; # Enable say feature say "Hello, World!"; # Output with a newline automatically say "Hello, again!"; # Output with a newline automatically

Perl print say output newline