Im new at perl and this script is in its infacy. I am writing a script where the user is prompted to enter an IP address. From the address entered, the program will determine its subnet and compare it with a file containing a list of all the subnets on the network. The PROBLEM is that I cant get the script to check the list and compare the stored subnet address with the list. The troubled area is in red. Im pretty sure I am doing wrong in regards to accessing the list. Here is my code:
#/usr/local/bin/perl # Creates a list of all subnets $sn = 0xffff & system("ypcat hosts | cut -f1-3 -d \".\" | sort -u | so +rt -k 1n,1 n -k 2n,2n -k 3n,3n -t \".\" -r>subnets.list"); # User is prompted to anter an IP address open(CHECK, ">check.list") || die "ERROR! This file cannot be created! +\n"; print "Enter an IP address.\n"; $ip = <STDIN>; chomp ($ip); $partial = rindex($ip, "."); $ip_subnet = substr($ip, 0, $partial); chomp ($ip_subnet); print CHECK "$ip_subnet\n"; # Checkpoint - prints subnet # Match entered subnet to active subnet list open(SUBNET, "subnets.list") || die "Unable to open file: subnets.list +\n"; while (<SUBNET> ) { if ($ip_subnet eq $subnet) { print "PASS\n"; } else { print "FAIL\n"; } }
So, for example, if the user enters 12.34.56.78, the program will store 12.34.56 as the subnet and then should compare 12.34.56 with the list subnets.list and return either a true or false value. Please HELP! Thanks. Zuinc

In reply to User input compared with generated list by zuinc

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.