構文 |
|
tell ファイル・ハンドル tell |
返り値 |
|
指定したファイル・ハンドルのファイル・ポインタの位置 |
説明
- 指定したファイル・ハンドルのファイル・ポインタの位置を返します。
- 引数を省略すると最後に読み込んだファイルが対象になります。
使用例
#!/usr/bin/perl
use strict;
use warnings;
my $position = 0;
while (my $line = <STDIN>) {
printf "%5d: %s", $position, $line;
$position = tell STDIN;
}
#!/usr/bin/perl
use strict;
use warnings;
my $filename = '/home/user1/test.txt';
open my $fh, "<", $filename or die "$!:$filename";
my $size = -s $filename;
my $position = 0;
while (my $line = <$fh>) {
printf "%4.1f%%: %s", ($position / $size * 100), $line;
$position = tell $fh;
}
close $fh;