Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Wondering if I could get some assistance.
Deleting paragraphs based on match in a hash.
Where I'm lost is getting the 'key' (PORNUM: *key*) from the paragraph in $_.
I'm very new to Perl, just a few long days/nights ... whatever they are!
Example data.#!/usr/bin/perl my @a, %hash; my $file = shift; open(list, "< $file") or die; chomp( @a=<list> ); close(list); @hash{@a}=@a; $/ = ""; # Example data # # $ cat hash # PP22x43@.5 # $ cat data # \n # Random lines # PORNUM: PP22x43@.5 # Random lines # \n # Random lines # PORNUM: PC12x120/25 while (<>) { ## manual test # print if !m/PORNUM: PP22x43@.5/ms; print unless exists $hash{ } } exit(0);
Example data file (Records have a leading blank line, first line is blank)PORNUM: PP22x43@.5 PORNUM: PC12x120/25
random lines of data PORNUM: PC21x21!2 random lines of data random lines of data random lines of data PORNUM: PP22x43@.5 random lines of data PORNUM: PP12x60@1 random lines of data random lines of data random lines of data PORNUM: PC12x120/25
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Deleting paragraphs based on match in a hash
by bart (Canon) on Sep 02, 2009 at 08:42 UTC | |
|
Re: Deleting paragraphs based on match in a hash
by spazm (Monk) on Sep 02, 2009 at 09:21 UTC | |
by Anonymous Monk on Sep 03, 2009 at 23:57 UTC |