Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

deleting elements from an array

Posted on 2000-04-04
3
Medium Priority
?
216 Views
Last Modified: 2012-05-04
I have an array like this:
@arrAlph = ('wer', 'abc', 'xyz', ... 'abc', ..);

I want to delete all the 'abc' s from it. They maybe at any position.
Is there an easy method?

0
Comment
Question by:leoleo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 200 total points
ID: 2686491
You can use grep to filter out all the 'abc's and assign redult to a new array.

@arrAlph = ('wer', 'abc', 'xyz', 'fds', 'abc', 'dds');
@newAlph = grep(!/abc/,@arrAlph);
# copy back to original array if needed
@arrAlph = @newAlph;
print(@arrAlph);

0
 

Author Comment

by:leoleo
ID: 2686786
Thanks.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2687314
#You can assign to the same array
@arrAlph = grep !/abc/,@arrAlph;
#but that will also elimitate elements like 'xyzabcdef'
#if you only want to eliminate 'abc'
@arrAlph = grep $_ ne 'abc',@arrAlph;
#or
@arrAlph = grep {$_ ne 'abc'} @arrAlph;
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question