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:

  1. Always use strictures (use strict; use warnings; - see The strictures, according to Seuss)
  2. Use the three parameter version of open and use lexical file handles: open my $inFile, '<', $fileName or die "Can't open $fileName : $!"
  3. foreach ($_) only iterates once so isn't doing anything interesting in your code
  4. Generally use explicit variables rather than the default variable in general code to make the code easier to read and to avoid nasty bugs due to $_'s contents changing at unexpected times

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;
True laziness is hard work

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.