Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: deleting a specific element from an array

by sugar (Sexton)
on Dec 03, 2008 at 02:33 UTC ( [id://727566]=note: print w/replies, xml ) Need Help??


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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: deleting a specific element from an array

Replies are listed 'Best First'.
Re^3: deleting a specific element from an array
by ikegami (Patriarch) on Dec 03, 2008 at 02:57 UTC

    I think you want

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

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

      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.

      it works :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://727566]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found