On Mon, 21 Feb 2005, Wagner, David --- Senior Programmer Analyst --- WGO wrote:
> Oliver Fuchs wrote: > > Hi, > > > > I want to save names from <STDIN> to an array. > > Afterwards I want to delete a single name in the array received again > > from <STDIN>. > > > > This is what I have: > > > > #!/usr/bin/perl > > > > use warnings; > > > > print "Some names please: \n"; > > @names = <STDIN>; > > print "Delete one name? \n"; > > $deleted = <STDIN>; > > foreach $item (@names) { > > unless ($item eq $deleted){ > > push (@aonly, $item); > > } > > }; > > print "Your names:\n", @aonly, "\n"; > > > > > > My question is how can I delete an element of the array directly > > (something like > > pop (@names, $item); > > ). > > Is there a chance to delete it without using the index? > > > > Oliver > > -- > > ... don't touch the bang bang fruit > > You would use splice to remove an item. But if I was going to do this, > then I would use a hash and then delete the item and not do the searching > through the array. If you only have 5 items, okay, but 10000 then you have to > search at least 5000 entires ( on avg ) to get your item. But if name is the > key into the hash, then one action to delete the name. > > Wags ;) > Hi, thanks for answering. So I have to use a hash ... will try it. Thanks Oliver -- ... don't touch the bang bang fruit -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>