I have an array representing all the names of files in a certain directory. I'm extracting certain file names out of text files, and then removing these file names from the array.
for example, say I have an array like this:
and I have a text file including all of the files to be removed from the list, which includes
.
I go through the file like so:
however, nothing happens... I assume that the 'grep' line would take everything that doesn't have the string and keep it in the array. Is there a better way? Could it be evaluating it like this:
instead of this:
? Could that be the problem?
If anybody has any suggestions, I'd be very grateful... What's the best way to remove individual items from an array in Perl?
I've also tried this:
and a few of the files are excluded, but not all of them... and I'm not sure why it picks these certain files either.
Thanks for any help you can offer. Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
for example, say I have an array like this:
Code:
@myarray = {"A File - My File1.txt", "A File - My File2.txt"};
and I have a text file including all of the files to be removed from the list, which includes
Code:
"File=A File - My File1.txt"
I go through the file like so:
Code:
open (FILENAME, "$textfile") or die "Can't open $playlist: $!";
@lines = <FILENAME>;
close FILENAME;
foreach $line (@lines) {
chop ($substring = substr ($line, index ($line, "=") + 1));
@myarray = grep(!/$substring/, @myarray) if ($line =~ /^File/);
}
however, nothing happens... I assume that the 'grep' line would take everything that doesn't have the string and keep it in the array. Is there a better way? Could it be evaluating it like this:
Code:
@myarray = grep(!/A File - My File1.txt/, @myarray) if ($line =~ /^File/);
instead of this:
Code:
@myarray = grep(!/A File \- My File1\.txt/, @myarray) if ($line =~ /^File/);
? Could that be the problem?
If anybody has any suggestions, I'd be very grateful... What's the best way to remove individual items from an array in Perl?
I've also tried this:
Code:
@myarray = grep(!/"$substring"/, @myarray) if ($line =~ /^File/);
and a few of the files are excluded, but not all of them... and I'm not sure why it picks these certain files either.
Thanks for any help you can offer. Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."