構文 |
|
print ファイル・ハンドル リスト print リスト |
返り値 |
|
出力成功時に真 |
説明
- リストの内容をファイル・ハンドルに出力します。
- ファイル・ハンドルを省略するとselectされている出力ファイル・ハンドル(通常は標準出力)に出力します。
- リストを省略すると$_が対象になります。
使用例
#!/usr/bin/perl
use strict;
use warnings;
print "Hello, world!\n";
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'output.txt';
open my $fh, ">", $filename or die "$!:$filename";
print $fh "Hello, world!\n";
close $fh;
#!/usr/bin/perl
use strict;
use warnings;
print STDERR "Hello, world!\n";
#!/usr/bin/perl
use strict;
use warnings;
my @items = ('one', 'two', 'three');
foreach (@items) {
print; # $_を出力
print "\n";
}
print "\n";
print @items, "\n"; # onetwothree
#!/usr/bin/perl
use strict;
use warnings;
my @items = ('one', 'two', 'three');
{
local $, = "__";
# このブロックの中だけ一時的に$,の値を変更する
print @items; # one__two__three
}
print "\n";