Hello everyone, I am very new to Perl. Any help would be greatly appreciated because I am stucked here for quite a long time :(

Basically what I am trying to do is:

1. I have a list of IP address in testingIP.txt

2. I want to loop through the text file and find out which IP address is in the net mask that I have specified using a PERL module that I have installed -- Net::Netmask http://search.cpan.org/~muir/Net-Netmask-1.9015/Netmask.pod

Unfortunately, it only works when there is only 1 IP address in testingIP.txt, this is my output for my current code:

Use of uninitialized value $i in bitwise and (&) at /usr/local/share/p +erl5/site_perl/5.26/Net/Netmask.pm line 411, <$fh> line 1. IP address: 192.168.1.1 is not inside 192.168.1.0/27 Use of uninitialized value $i in bitwise and (&) at /usr/local/share/p +erl5/site_perl/5.26/Net/Netmask.pm line 411, <$fh> line 2. IP address: 192.168.1.2 is not inside 192.168.1.0/27 Use of uninitialized value $i in bitwise and (&) at /usr/local/share/p +erl5/site_perl/5.26/Net/Netmask.pm line 411, <$fh> line 3. IP address: 192.168.1.3 is not inside 192.168.1.0/27 IP address: 192.168.1.4 is inside 192.168.1.0/27

This is my code

#!/usr/bin/perl use strict; use warnings; use Net::Netmask; my $filename = 'testingIP.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $block = Net::Netmask->new("192.168.1.0/27"); while (my $row = <$fh>){ my @row = $row; for (my $i=0; $i < scalar(@row); $i++){ if ($block->match($row[$i])){ print "IP address: $row[$i] is inside $block\n"; } else{ print "IP address: $row is not inside $block\n"; } } }

In reply to Use of uninitialized value $i in bitwise and (&) at <Netmask.pm> by dotowwxo

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.