-2

perlでgrepを使いたいのですが、ここで混乱しています。私がやりたいのは、次のようなファイルが1つあります-

this is abctemp1
this is temp2
this is temp3x
this is abctemp1

ここで、パターン 'temp' を使用してこのファイルから一意の単語、つまり 'abctemp1, temp2, temp3x' を抽出し、それを配列に格納したいと考えています。これを行う方法?

4

2 に答える 2

1
use strict; use warnings;

my (@array, %seen);
/(\w*temp\w*)/ && !$seen{$1}++ && push @array, $1 while <DATA>;
print "$_\n" for @array;

__DATA__
this is abctemp1
this is temp2
this is temp3x
this is abctemp1
于 2013-07-10T08:16:25.323 に答える