in reply to How to ignore lines that match certain string after it is matched for the first time within a same file
Perhaps the following will work for you:
use strict; use warnings; my ( @array, %seen ); while ( my $line = <DATA> ) { if ( $line =~ /(amazing\.\S+)/ and not $seen{ lc $1 }++ ) { push @array, $line; #print $line; } } print for @array; __DATA__ Today is amazing.nice day Today is amazing.nice but still I haven't done anything Yesterday was just a normal day Tomorrow probably will be amazing.new day
Output:
Today is amazing.nice day Tomorrow probably will be amazing.new day
$1 captures amazing\.\S+ and using lc on the hash key helps insure case is not significant in uniqueness.
Hope this helps!
|
|---|