in reply to Checking Input using reg exp.

You have some brackets messed up. I have this compiling.
You should really use CGI.pm for this. If you are looking for a quick but excellent CGI tutorial check out Ovid's page. Right at the top is a link to his CGI course.
I also added a few quick comments.
#!/usr/local/bin/perl -w $cnip = $ENV{'QUERY_STRING'}; print "\n Look Up NPANXX Info"; print "\n =============================="; print "\n Please enter NPANXX:_______\b\b\b\b\b\b\b +"; chomp($cnip=<STDIN>); if($cnip =~ /\d{6}/){ @datb = `cat tech3 | grep $cnip`; #You could do this a a file open + and grep the contents... it would be more portable and perlyer :) @cnip = $cnip; #printing the info foreach $datb (@datb){ @cnip = split (\/\:/, $datb); print "\n ===================================== +===\n"; print " NPANXX Line Switch MSR&CUSTGP VMX"; print " $cnip $cnip[1] $cnip[2] $cnip[3] $cnip[4] $cnip +[5]"; print " ======================================= +=\n\n"; } @datb = `cat tech3 | grep $cnip`; @cnip = $cnip; #printing the info foreach $datb (@datb){ @cnip = split (\/\:/, $datb); print "\n ===================================== +===\n"; print " NPANXX Line Switch MSR&CUSTGP VMX"; print " $cnip $cnip[1] $cnip[2] $cnip[3] $cnip[4] $cnip +[5]"; print " ======================================= +=\n\n"; } } else { ### you has this left bracket way up under your 'if' print "\nValid NPANXX not entered!\n"; }
HTH

grep
grep> cd pub grep> more beer

Replies are listed 'Best First'.
Re: Re: Checking Input using reg exp.
by Beatnik (Parson) on Dec 28, 2001 at 18:03 UTC
    If you look closely, you'll see this isn't CGI code... just VERY dirty shell code. He probably got you fooled by that $cnip = $ENV{'QUERY_STRING'}; line. Note that he's not printing any HTTP headers (which is kinda trivial for CGI scripts). I can only assume that there is actually an environment variable called QUERY_STRING. A ++ for your comments on perlier code and your fixes on his referencing attempt tho :-)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: Re: Checking Input using reg exp.
by defyance (Curate) on Dec 28, 2001 at 07:09 UTC
    Cool, I got it figured out. Its working great now. Now to make it look a bit perlyer, he he. I've been working with C and Shell progs most of my natural programming life, he he. Here is the working code:

    #!/usr/local/bin/perl $cnip = $ENV{'QUERY_STRING'}; print "\n Look Up NPANXX Info"; print "\n =============================="; print "\n Please enter NPANXX:_______\b\b\b\b\b\b\b +"; chomp($cnip=<STDIN>); if($cnip =~ /\d{6}/){ &npa1 } else{ print "\n Valid NPANXX not entered!\n"; }; sub npa1 { @datb = `cat tech3 | grep $cnip`; @cnip = $cnip; #printing the info foreach $datb (@datb){ @cnip = split (/\:/, $datb); print "\n ========================================\n"; print " NPANXX Line Switch MSR&CUSTGP VMX"; print " $cnip $cnip[1] $cnip[2] $cnip[3] $cnip[4] $cnip +[5]"; print " ========================================\n\n"; }; };



    I'll make it prettier and stuff, TEAR IT APPART PLEASE!!
      Perltidy will help you clean it up and "make it prettier".

      If things get any worse, I'll have to ask you to stop helping me.

      You don't need to escape the ':' in the regex.
      @cnip = split /:/, $datb
      will do fine.

      Also using cat & grep seems a bit messy, what about:

      use File::Slurp; @datb = grep { /$cnip/ } read_file('tech3');