Code critique

J. J. Horner jhorner at 2jnetworks.com
Fri Jan 18 22:38:09 CST 2002


* Kevin Guidry (kguidry at utk.edu) [020118 17:41]:
> 	Much thanks in advance.
> 
> 	The code is, in its present form, just a method of getting three
> pieces of information from a user at the console, inserting them
> into a command, and then exec'ing that command.  The specific pieces of
> info are IP address, subnet mask, and gateway.  I do a quick check to make
> sure that they all "look" like IP addresses before passing them to the
> command.  The specific command is a Windows 2000 command "netsh" which
> allows, among other things, you to change your network settings from the
> command line.  In this case, I am just changing the three afore mentioned
> items on a laptop that will be moved around quite a bit.

A couple of notes:

1.  Look up Regexp::Common on CPAN.  Good basic regular expressions 
to check an number of things, in this case, the IP.

Usage

#!/bin/perl
use Regexp::Common;

while(<DATA>) {
  if(/$RE{net}{IPv4}{december}{-keep}/) {
    print "IP Address: $1\n";
  }
}

__DATA__
24.113.50.245
0.42.523.2
255.242.52.4
2.5.3

2.  It is okay to use any effective method to check user input, 
as long as it is readable, maintainable, and reasonably efficient.
I often do the same thing as you, but instead of just printing out a
message, I may create a has with different messages assigned to numbers,
then as my subroutines finish, I have them return a status code that
matches one of the keys in the hash.  I then just print out the code.
If you end up writing larges amounts of code, and you find this method
helps you in some way, use it.

3.  One thing that may help your code:  BUY THE PERL CD BOOKSHELF!!  Honestly,
for ~$60.00 it was the best investment I ever made.  The version I got came with:

- Learning Perl
- Learning Perl on Win32
- Perl Cookbook (a must have, if you ask me)
- Advanced Perl Programming
- Programming Perl
- Perl in a Nutshell.

I hear the newer version comes with Perl for the SysAdmin.  Must be cool.  I just 
copied content over to my webserver and now I have an online reference from anywhere
in the world.  Just a simple login and I'm golden!

4.  A good place to get help and view good code, as well as learn more information:
http://www.perlmonks.org/ .  Randal Schwartz hangs out there occasionally.

If you have any more questions, let me know.

Thanks
JJ
-- 
J. J. Horner
"H*","6a686f726e657240326a6e6574776f726b732e636f6d"
***************************************************
"H*","6a6a686f726e65724062656c6c736f7574682e6e6574"

Freedom is an all-or-nothing proposition:  either we 
are completely free, or we are subjects of a
tyrannical system.  If we lose one freedom in a
thousand, we become completely subjugated.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
Url : http://mail.pm.org/archives/knoxville-pm/attachments/20020118/31e665ce/attachment.bin


More information about the Knoxville-pm mailing list