Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 913349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:32:35+00:00 2026-05-15T17:32:35+00:00

I need to walk over an array, and conditionally delete elements, in Perl. I

  • 0

I need to walk over an array, and conditionally delete elements, in Perl. I know about slice, but am not sure how to use it in a foreach context.

In Ruby, there is reject!:

foo = [2, 3, 6, 7]
foo.reject! { |x| x > 3 }
p foo   # outputs "[2, 3]"

Is there a Perl equivalent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:32:35+00:00Added an answer on May 15, 2026 at 5:32 pm

    You can use Perl’s grep which acts like an inverted reject: it will keep all items which satisfy the condition. So reject x > 3 must become grep x <= 3:

    @foo = (2, 3, 6, 7);
    @foo = grep { $_ <= 3 } @foo;
    print @foo; # 23
    

    The condition does not have to be a numeric comparison but can be anything that works in boolean context, e.g. matching against a regular expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been covered over and over but I just can't understand
I have to walk a tree that reaches me from a NodeList, I need
in programming there is often such tasks walk through in multi dimensional array (for
I need a simple AI script to make a zombie object 'walk' around randomly.
I need to walk or interact across all nodes and child nodes with VB.NET
This is not a homework. Visually it looks like a tree, but all leafs
I just started thinking about creating/customizing a web crawler today, and know very little
I need to iterate over nested lists and dictionaries and replace every integer trough
I need to walk a folder tree in C# and somehow record what I
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.