Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to ignore lines that match certain string after it is matched for the first time within a same file

by Kenosis (Priest)
on Sep 19, 2012 at 23:47 UTC ( #994564=note: print w/ replies, xml ) Need Help??


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!


Comment on Re: How to ignore lines that match certain string after it is matched for the first time within a same file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994564]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2015-07-05 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls