in reply to deleting a non-numeric scalar within array
You're printing $line - can't you see that it is not numeric and thus can't be used as an array index?
One way is by changing the for loop (and some other modifications to improve your code):
use strict; use warnings; open my $HOSTS, "<", "/etc/hosts" or die "Cannot open hosts file!\n"; my @hosts = <$HOSTS>; close $HOSTS; for my $line (0..$#hosts) { if ($hosts[$line] =~ /($ARGV[0])/) { print "$hosts[$line]"; delete $hosts[$line] } }
|
|---|