Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: "Modification of non-creatable array value attempted, subscript -1" Error

by Anonymous Monk
on Oct 26, 2011 at 07:04 UTC ( [id://933807] : note . print w/replies, xml ) Need Help??


in reply to "Modification of non-creatable array value attempted, subscript -1" Error

My brother at one time, long ago in the mid 90's, tried to create a program in Visual Basic without any programming experience... --He threatened to name his next dog, "Subscript Out Of Range." An array always has a size, even if it's empty. When you access array elements by their index number, you are, in less common terms, actually using a "subscript" number. In perl, array index/subscript numbers are positive integers starting at 0 for the first element. If an array is accessed in scalar context, it will return the number of elements in the array. If an array is empty in perl (no elements) and accessed in scalar context, it will return -1, an invalid index/subscript for all arrays. As a perl beginner, you're missing some of the basics, namely always use 'strict' and 'warnings' and while developing, also using 'diagnostics' can be real helpful.
#!/usr/bin/perl use strict; use warnings; use diagnostics; # this makes error messages nicer.
As for the problem with your code, I'd bet you have a blank line in your input file. You're not checking $_ (default input), so you'd be feeding an empty string into Net::Whois::ARIN.
#!/usr/bin/perl use strict; use warnings; use diagnostics; # this makes error messages nicer. use Net::Whois::ARIN; my $file="file_containing_IPs.txt"; open(LIST,$file) or die "Unable to open file $file:$!\n"; my $w = Net::Whois::ARIN->new( host => 'whois.arin.net', port => 43, timeout => 30, ); while(<LIST>) { foreach ($_) { chomp; if(defined $_ && $_) { my @output = $w->network($_); foreach my $net (@output) { printf( "CIDR: %s\tNetName: %s\tNetHandle: %s\n", $net->CIDR, $net->NetName, $net->NetHandle, ); } } } } close(LIST);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://933807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-02-06 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found