in reply to Subtracting Lists

Hello, I'm relatively new to PERL and have a pretty basic question.

I personally believe that the very fist thing you should know is that it's not PERL.

Is GREP usable in this instance?

It's certainly usable. But it all depends on the code you tell it to execute. One common technique to check whether and item belongs to an array used to involve another grep, but that would be inefficient, since it would iterate over all items of the bad list. Thus a better choice would be List::Util's first() which stops as early as an item is found. With 5.10, however, you have a specialized operator to do this kinda things: ~~:

#!/usr/bin/perl use strict; use warnings; use 5.010; my @goodstuff=1..5; my @badstuff=(1,3); my @newstuff = grep !($_ ~~ @badstuff) => @goodstuff; say "@newstuff"; __END__

Incidentally, to refer to the grep() function, you don't need to capitalize its name and better would not, since it has little to no sense at all, given that Perl is case sensitive. Instead, here, you can link to its documentation like I did above by inserting the following code in the source of the post: [doc://grep]. Alternatively you can use the trick one commonly adopts in pure text contexts of adding a pair of parens to remind that it's a function, optionally putting it in code tages -here at the monastery- to remind that it's supposed to be code, as in: <code>grep()</code>.

--
If you can't understand the incipit, then please check the IPB Campaign.