Hello all,
I'm trying to simplify my subroutine that is supposed to open an (LDIF)text file, read in its contents into an array then print to a new file while excluding the lines that exist in another array.
I can currently accomplish this with just the word I want to exclude, but of course this leads to bloated code because I have to continuously open and close the file on each removal.
Here is what I have so far:
sub GROOMLDIF {
# Delete LDAP-internal fields
my @erasethese = qw(structuralObjectClass entryUUID creatorsName
+ modifiersName createTimestamp modifyTimestamp entryCSN);
open(FILE,"< data/all.ldif");
my @LINES = <FILE>;
close(FILE);
open(FILE,"> data/groomed.ldif");
foreach my $LINE (@LINES) {
my @array = split(/\:/,$LINE);
print FILE $LINE unless ($array[0] eq "$erasethese[0]");
}
close(FILE);
open(FILE,"< data/groomed.ldif");
@LINES = <FILE>;
close(FILE);
open(FILE,"> data/groomed.ldif");
foreach my $LINE (@LINES) {
my @array = split(/\:/,$LINE);
print FILE $LINE unless ($array[0] eq "$erasethese[1]");
}
close(FILE);
}
I would like to combine all of them into one open/close. I've tried a nested for-loop that incremented with no luck.
Any help would be appreciated.
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.