411 REFERENCE · Wikibooks
Perl Programming/Keywords/print
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Perl pos printf Keywords
The print keyword
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
print FILEHANDLE LIST
print FILEHANDLE
print LIST
print
Examples
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";
See also
printf
select
sprintf
Perl pos printf Keywords