On Mon, 21 Feb 2005, Bob Showalter 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;
> 
> We always recommend:
> 
>   use strict;
> 
> >
> >print "Some names please: \n";
> >@names = <STDIN>;
> >print "Delete one name? \n";
> >$deleted = <STDIN>;
> >foreach $item (@names) {
> >unless ($item eq $deleted){
> >push (@aonly, $item);
> >}
> >};
> 
> This can be written as:
> 
>   @aonly = grep $_ ne $item, @names;
> 
> or, if you just want one array:
> 
>   @names = grep $_ ne $item, @names;
> 
> >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?
> 
> No; you have to know the index, or use a hash instead of an array.
> 

Thanks for your help. So i will try to use a hash.

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>


Reply via email to