Home » Howtos » Perlfunc » Print function |
The print function prints a string, or list of strings to your screen, or to a file.
#!/usr/bin/perl use strict; use warnings; print "Hello there\n";
Hello there
#!/usr/bin/perl use strict; use warnings; print "Hello there - ", "this is a longer example\n";
Hello there - this is a longer example
#!/usr/bin/perl use strict; use warnings; print "Here's a calculation: " . 12 * 3 . "\n";
Here's a calculation: 36
#!/usr/bin/perl use strict; use warnings; open FILE, ">output.txt" # Create the file "output.txt" or die "Could not create file: $!"; # in the current directory print FILE "Hello there\n"; # Print a string to the file close FILE # Close the file or die "Could not close file: $!";
The file will contain:
Hello there
To find out more, run the command:
perldoc -q print