Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 contemplating the Monastery: (4)
As of 2016-10-01 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (9 votes). Check out past polls.