Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 meditating upon the Monastery: (21)
As of 2014-07-25 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls