Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: splice help - deleting specific element

by mpeever (Friar)
on Oct 17, 2008 at 16:52 UTC ( [id://717802]=note: print w/replies, xml ) Need Help??


in reply to splice help - deleting specific element

grep is the correct command, it just looks like your grep block needs tuning. If the company names are just strings, you ought to be able to use:
@allcompanies = grep { not $_ eq $co } @allcompanies
Notice if there are duplicates, this will whack all of them.

Replies are listed 'Best First'.
Re^2: splice help - deleting specific element
by JavaFan (Canon) on Oct 17, 2008 at 17:15 UTC
    While not $_ eq $co isn't incorrect, I rather write $_ ne $co.
    Notice if there are duplicates, this will whack all of them.
    That's easily solved:
    my $i = 0; @allcompanies = grep {$_ ne $co or $i++} @allcompanies;
      While not $_ eq $co isn't incorrect, I rather write $_ ne $co.

      I like yours better too.

      About duplicates: I assume whacking dups is actually what was intended based on the problem description, but I thought it would be worthwhile to mention that side-effect.

Re^2: splice help - deleting specific element
by kathys39 (Acolyte) on Oct 17, 2008 at 17:07 UTC
    works like a charm. guess that is why I should always have use warnings on, right? thanks again-

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2026-05-10 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.