簡単に言えば、Perl を使用して、ファイルからテキストを抽出し、そのテキストを新しいファイルに保存したいと考えています。
これまでのところ、私のコードは次のとおりです。
#!/usr/local/bin/perl
use warnings;
use strict;
use File::Slurp;
use FileHandle;
use Fcntl qw(:DEFAULT :flock :seek); # Import LOCK_* constants
my $F_IN = FileHandle->new("<$ARGV[0]");
my $F_OUT = FileHandle->new(">PerlTest.txt");
while (my $line = $F_IN->getline) {
$line =~ m|foobar|g;
$F_OUT->print($line);
# I want to only copy the text that matches, not the whole line.
# I changed the example text to 'foobar' to avoid confusion.
}
$F_IN->close();
$F_OUT->close();
明らかに、それは行をコピーしています。行全体ではなく、ファイルから特定のテキストを抽出して印刷するにはどうすればよいですか?