Perl Programming/Keywords/print
Appearance
The print keyword
[edit | edit source]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 | edit source] print FILEHANDLE LIST
print FILEHANDLE
print LIST
print
Examples
[edit | edit source] The code
$filename = "assign.pl";
print $filename . "\n";
open(my $fh, "<", $filename)
or die "cannot open < " . $filename . ": $!";
read $fh, $f, 1024;
print $f;
close($fh);
returns the contents of the file "assign.pl":
assign.pl $tmp = "909135790159"; print $tmp . "\n"; $tmp =~ y/13579/24680/; […] print $tmp . "\n";