in reply to Re^2: deleting a specific element from an array
in thread deleting a specific element from an array

I think you want

my $dels = join '|', map quotemeta, @dels; @array = grep !/$dels/, @array

That deletes "applepie" when "apple" is in @dels.

Replies are listed 'Best First'.
Re^4: deleting a specific element from an array
by oko1 (Deacon) on Dec 03, 2008 at 03:10 UTC

    Of course, if you only wanted to delete exact matches, you could extend ikegami's solution like so:

    @array = grep !/^($dels)$/, @array;

    Now, 'apple' will no longer result in 'apple pie' being deleted.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf

      Now, 'apple' will no longer result in 'apple pie' being deleted.

      ...but "apple\n" still gets tossed. Use \z to match the literal end-of-string and $ for end-of-string-or-newline-you-know-whatever.

        Why, no - it doesn't.

        ben@Tyr:~$ perl -wne'print length, ": $_" if /^(apple)$/' apple 6: apple

        '$' in regular expressions matches before '\n'.


        --
        "Language shapes the way we think, and determines what we can think about."
        -- B. L. Whorf
Re^4: deleting a specific element from an array
by sugar (Beadle) on Dec 03, 2008 at 03:28 UTC
    it works :)