Perl Programming/Keywords/print

Previous: pos Keywords Next: printf

The print keyword Edit

print prints a string or a list of strings and returns true, if successful. The parametre FILEHANDLE may be a scalar variable with a reference to the file handle. This introduces a level indirection for the print.

If FILEHANDLE is a variable followed term, it may be misinterpretedby the system as an operator unless a + is added inbetween, or all arguments are put in parentheses. Without the FILEHANDLE, the last selected output handle is used. Without LIST, the function prints $_ to the current output handle.

To use FILEHANDLE and use the $_, a real filehandle like FH and not an indirect filehandle like $fh is required.

Syntax Edit

  print LIST

Examples Edit

  The code
	$filename = "";
	print $filename . "\n";

	open(my $fh, "<", $filename) 
		or die "cannot open < " . $filename . ": $!";

	read $fh, $f, 1024;

	print $f;

returns the contents of the file "":
 $tmp = "909135790159";
 print $tmp . "\n";
 $tmp =~ y/13579/24680/;
 print $tmp . "\n";

See also Edit

Previous: pos Keywords Next: printf