deleting items from array - better way? 
Author Message
 deleting items from array - better way?

Hi all,

I want to delete all values from an array that match $val.  Note that I
don't want to merely replace them with null strings (defined or not).  I dug
around the "one-liners" section of TPJ, the cookbook and this newsgroup but
didn't see one.

e.g. Get rid of all values that match "one".

my $val = 'one';
# Begin 2 liner
my $n = 0;

Can I cut this from a 2-liner to a 1-liner?  Is there a better way?

Thanks in advance.

Regards,

Mr. Sunblade



Mon, 01 Mar 2004 20:56:26 GMT  
 deleting items from array - better way?

Daniel> I want to delete all values from an array that match $val.  Note that I
Daniel> don't want to merely replace them with null strings (defined or not).


--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Mon, 01 Mar 2004 20:59:23 GMT  
 deleting items from array - better way?

Quote:

> Hi all,

> I want to delete all values from an array that match $val.  Note that I
> don't want to merely replace them with null strings (defined or not).  I dug
> around the "one-liners" section of TPJ, the cookbook and this newsgroup but
> didn't see one.

perldoc -f grep


Mon, 01 Mar 2004 21:05:31 GMT  
 deleting items from array - better way?

Quote:

> Hi all,

> I want to delete all values from an array that match $val.  Note that I
> don't want to merely replace them with null strings (defined or not).  I dug
> around the "one-liners" section of TPJ, the cookbook and this newsgroup but
> didn't see one.

> e.g. Get rid of all values that match "one".

> my $val = 'one';
> # Begin 2 liner
> my $n = 0;


  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I doubt that does what you want- in fact I think it looks like


when you are done.

Here's some one-liners that should work:

  # mostly matching values

  # mostly non-matching values

--
Joe Schaefer    "Few things are harder to put up with than the annoyance of a
                                        good example."
                                               --Mark Twain



Mon, 01 Mar 2004 21:17:31 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Deleting an item from an array

2. Deleting items from an array

3. Delete item from the middle of @array?

4. Help on deleting an item in an array?

5. How can i delete an item in the middle of an array

6. How to delete items from an array?

7. Help Needed: Delete an Line or Array Item

8. Seeking advice on semantics (pros / cons and best ways of) using constants across modules

9. Better ways to deal with yppasswd?

10. Better ways to do this?

11. Better ways to...

12. Any better ways of doing this ?

 

 
Powered by phpBB® Forum Software