rycher has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Clearing lines in a file based on an array containing the lines
by almut (Canon) on Apr 22, 2009 at 20:32 UTC | |
by Anonymous Monk on Apr 22, 2009 at 20:54 UTC | |
|
Re: Clearing lines in a file based on an array containing the lines
by ramrod (Priest) on Apr 22, 2009 at 20:27 UTC | |
|
Re: Clearing lines in a file based on an array containing the lines
by toolic (Bishop) on Apr 22, 2009 at 20:33 UTC | |
|
Re: Clearing lines in a file based on an array containing the lines
by jwkrahn (Abbot) on Apr 22, 2009 at 23:33 UTC | |
|
Re: Clearing lines in a file based on an array containing the lines
by NiJo (Friar) on Apr 23, 2009 at 18:12 UTC |