Your code is pretty close to working.
Problems and changes:
- You have two definitions for the contents of your hash file. Will the hash file have "PORNUM: " prefixed on each line?
- turn on strictures: use strict; use warnings, they'll catch problems like your use of a possible reserved word 'list'.
- some clean-up: let's use the 3 argument form of open, with a lexically scoped filehandle. Get into this habit early.
- Let's skip blank lines in the hash file, to make it easier for your users to be correct.
- If you're going to modify global special variables, like $/ you'll want to make a local copy with local. And put them in as small of a scope as possible, I've added a brace block around the local to make it clear to future readers of the code that this is the planned scope of the change to $/
#!/usr/bin/perl
use strict;
use warnings;
my %skip;
my $file = shift;
open(my $list, '<', $file) or die;
while(<$list>)
{
chomp;
next if /^$/; #skip blank lines in hash file
#assumes that hash file is just the ID, without umPORN prefix
$skip{ $_ }=1;
}
close($list);
{
local($/)="";
while (<DATA>)
{
next if ( m/ PORNUM: \s+ (.*) $ /mx && $skip{ $1 } );
print "-$_-";
}
}
__DATA__
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.