Quick Question...

I'm having issues. All I'm doing is opening a file, finding the data read by STDIN, and prints the found data to the terminal. If the data is not found, I want it to error out, and write STDIN to a log. This should be simple, but I'm obviously doing something wrong, and can't seem to find the err in my ways.. Please take a look at the below code:

The code does use strict and -w, it declares the var's using use vars qw($var);.

sub npa { #This purdy little thing searches the NPA-NXX given to STDIN #Then it prints the happy little output to the terminal. print "\n", " " x 31, "Look Up NPANXX Info\n"; print " " x 27, "=" x 30, "\n"; print " " x 30, "Please enter NPANXX:"; chomp( $cnip = <STDIN> ); if ( $cnip =~ /\d{6}/ ) { &npa1; } else { &err2; } sub npa1 { open( TECH, "</export/home2/knxvcs/knxvcs56/ttu/npalist" ) || die "Oops : $!"; while (<TECH>) { if ( $cnip / ) { (@npa) = split (/\:/); print "\n", " " x 14, "*" x 60; print "\n", " " x 24, "=" x 40, "\n"; print " " x 24, "NPANXX Line Switch MSR&CUSTGP VMX +\n"; print " " x 24, "$npa[0] $npa[1] $npa[2] $npa[3] $npa[4] $npa +[5]\n"; print " " x 24, "=" x 40, "\n\n"; &con; } else { &err3($cnip) } } close(TECH); #Close file } }
Then err3 sub will put the unfound data from STDIN to a log file like so:
sub err3 { #Woah man.. print "\n" x 2; print " " x 20, "Selection Not Found! Press <Enter> to Continue"; <>; open(ERRLOG, ">>/export/home2/knxvcs/knxvcs56/ttu/errlog") || die "Oops : $!"; print ERRLOG "$cnip\n"; close(ERRLOG); system("clear"); menu(); }

This should be so simple, but I don't know what the heck I'm doing wrong!! If it doesn't find any data, it processes what the else tells it to do, and move on happily, or thats the way I think it should go.. It seems that its not finding any of the data, because even if I put something in that I know is in the data file, it sends me to the &err3 sub, and puts the unfound data into the log file. If I comment out else { &err3($cnip) }, it finds the data that it should happily, and moves on. Like I said IT WORKS When I uncomment the else { &err3($cnip) } line, aside from not erroring out if data isn't found....Am I overlooking something simple? If so, go easy on me, I've had a bad day..

Any ideas??


perl -e '$a="3567"; $b=hex($a); printf("%2X\n",$a);'

edited: ~Sat Jul 13 16:10:32 2002 (GMT)
by footpad: Added <readmore> tag, per Consideration.


In reply to Is it there, or is it not?? Quirkiness with error handling. by defyance

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.