Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 having an uproarious good time at the Monastery: (7)
As of 2014-12-21 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls