Massyn has asked for the wisdom of the Perl Monks concerning the following question:
#!/fellow/monks.pl
A collegue of mine asked me "How do you delete an entry out of an array?" I know that "delete" can zap an entry out of a hash, but what do you use to delete an entry out of an array? He went and wrote this piece of code, which does the trick pretty well.
Is there a single line perl statement, like delete that will do the same thing? My "Programming Perl" didn't reveal anything obvious.
sub delArrayEntry() { my @array1 = @_; my @array2 = ""; foreach $entry (@array1) { if ($entry ne $current_log) { push @array2,$entry } } }
Thanks!
#!/massyn.pl
You never know important a backup is until the day you need it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Deleting an array entry
by dws (Chancellor) on Nov 28, 2002 at 04:31 UTC | |
|
Re: Deleting an array entry
by pg (Canon) on Nov 28, 2002 at 05:00 UTC | |
|
Re: Deleting an array entry
by bart (Canon) on Nov 28, 2002 at 07:03 UTC | |
by Jaspersan (Beadle) on Nov 28, 2002 at 17:56 UTC | |
|
Re: Deleting an array entry
by rbc (Curate) on Nov 28, 2002 at 04:34 UTC | |
|
Re: Deleting an array entry
by chromatic (Archbishop) on Nov 29, 2002 at 00:38 UTC |