in reply to The error says the value is uninitialized, but it works anyway
Besides being clearer, this also works with n elements in whatever array, whereas your solution hardcodes two elements in the @drop.use strict; use warnings; my @colors = qw(red green blue yellow pink purple brown); my @drop = qw(pink brown); foreach my $drop_color (@drop) { my $index = 0; foreach my $color (@colors) { if ( $color eq $drop_color ) { splice (@colors, $index, 1); last; } $index++; } } print "@colors \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The error says the value is uninitialized, but it works anyway
by jcb (Parson) on Aug 19, 2019 at 00:42 UTC | |
by soonix (Chancellor) on Aug 19, 2019 at 08:36 UTC | |
by AnomalousMonk (Archbishop) on Aug 19, 2019 at 17:27 UTC |