This is my current code:
#!/usr/bin/perl -w use strict; require IO::Socket; while (<>) { chomp(my $host = $_); my @header; print "Connecting to: $host\n"; my $socket = new IO::Socket::INET( PeerAddr => $host, PeerPort => 80, Proto => 'tcp') || print "Could not connect: $!\n"; print "Connected.\n"; print $socket "GET / HTTP/1.0\n\n"; my $i = 0; while (<$socket>) { @header[$i] = $_; $i++; } $i = 0; print "--------------------------------------\n"; while ($i <= 8) { print "@header[$i++]"; } print "-------------------------------------\n"; print "Finished $host\n\n"; }
If, when I go through the list of IP addresses and the host is denied, instead of continuing with the next IP address, it will give me the error "Cannot use string (" 1 ") as a ref character, whereas" strict refs "in use".
If I then changed @header [$ i] = $; to $ header [$ i] = $; I am also getting the same error. How can I make this script better.
source share