Can anyone let me know what I'm doing wrong?
Well, a bunch of stuff really. Or at least, if not wrong, then sub-optimum. But not so much that would generate the error you describe. My best guess at the cause of your error is that one of your calls to the module is failing (no entries in a list perhaps) and that code that is called subsequently is making bad assumptions. The error itself is caused by trying to modify the last element (the -1 bit) of an empty array - the element doesn't exist and can't be modified. You are using a rather old version of Perl and possibly an old version of the module so the first thing that would be worth trying is updating to the latest version of the module.
As for the other stuff I alluded to:
I'd rework the code to look something like the following (untested):
#!/usr/bin/perl use strict; use warnings; use Net::Whois::ARIN; my $file = "file_containing_IPs.txt"; open my $inFile, '<', $file or die "Unable to open $file: $!\n"; my $w = Net::Whois::ARIN->new ( host => 'whois.arin.net', port => 43, timeout => 30, ) or die "Can't access server: $!\n"; while (defined (my $line = <$inFile>)) { chomp $line; next if !length $line; for my $net ($w->network ($line)) { printf "CIDR: %s\tNetName: %s\tNetHandle: %s\n", $net->CIDR, $net->NetName, $net->NetHandle; } } close $inFile;
In reply to Re: "Modification of non-creatable array value attempted, subscript -1" Error
by GrandFather
in thread "Modification of non-creatable array value attempted, subscript -1" Error
by techie411
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |