我有这个文件:
1. heavenns 2 heavenns 3 heavenns good 4 heavenns 5heavennly bye
从这一行开始,只有'heavenns'
and'heavennly'
应该打印一次。
我这段代码是我在其他线程中提出的另一个问题。我想我已经在那里接受了我的问题,现在没有人会看到它,对吧?(我是新来的,不知道怎么用?)
#!/usr/bin/env perl
use strict;
use warnings;
my $regex = "heavenn+";
my $rx = qr/$regex/;
print "Regex: $regex\n";
my $file = "myfilename.txt";
my %list;
my @myarr;
open my $fh, "<", $file or die "Failed to open $file: $?";
while ( my $line = <$fh> ) {
if ($line =~ $rx)
{
print $line;
$list{$line}++;
}
}
push @myarr, sort keys %list;
print "Mylist: @myarr\n"; #NOT GIVING ME UNIQUE VALUES & NOW I ONLY WANT heavenns and heavennly