Jeff / Joseph, Thanks for you replies. Appologies about commenting out the 'use strict'. I was playing about with the program and was checking the different errors I got with and without it. Didn't realised it was still commented when I posted.
Its funny, but I spent about an hour trying to get this thing to work. When I woke up this morning, the answer (well idea of what it was) poped into my head. Jeff just confirmed this (and gave me a few pointers on how to go about it) I will include the error next time. (i'm sure there will be a next time :)) Thanks again. > > From: "R. Joseph Newton" <[EMAIL PROTECTED]> > Date: 2003/09/27 Sat AM 04:59:35 GMT > To: Gedi <[EMAIL PROTECTED]> > CC: [EMAIL PROTECTED] > Subject: Re: subroutine problem > > Gedi wrote: > > > Hi all, > > > > I have recently started to learn perl. After reading Randal Schwartz’s > > Learning perl, I decided to give my first program a whirl. > > Upon writing it, I was checking each section of code as I went along to > > make sure everything worked. > > > > I got to one section and couldn’t get it to run as a subroutine. I don’t > > fully understand the error I am getting and am hoping somebody can point > > me in the right direction. > > > > Here is a snippet of my code (edited/reduced to about ¼ of the full > > size) which gives the same error as my full program. > > What error? It helps to paste in the error message, as well as marking the > line numbers it references. > > > #usr/bin/perl -w > > > > #use strict; > > Nuh-uh. You are not ready for help from others when you refuse it from your > compiler. Strict compilation should ALWAYS be your first line of defense > against logic errors. > > > > > use warnings; > > use IO::Socket; > > > > print "1. network Listing only\n"; > > print "2. Port scan only\n"; > > > > print "\nPlease enter selection: "; > > chomp (my $selection = <STDIN>); > > > > if ($selection == 1) { > > #bla bla, don't need this info > > } > > elsif ($selection == 2) { > > print "\nEnter target: "; > > chomp(my $target = <STDIN>); > > print "Enter start port: "; > > chomp(my $port = <STDIN>); > > print "Enter end port: "; > > chomp(my $end_port = <STDIN>); > > &scan; > > I don't know if this is the error line, but it is not good. Only use this > when you are handing a function reference to a callback. Under normal > circumstances, you should use scan(); > > > > > } > > > > > > sub scan { > > > > print "Scanning $target | from port $port to $end_port\n\n"; > > Where idid these variables come from. No such variables have been declared > within either the scope of the function or the main namespace. I notice, > though that you do declare and assign values to, then never use, > similarly-named variables within an elsif block above. Did you mean to > declare them in the main namespace, then assign them within the else block? > > > foreach (; $port<=$end_port; $port++) { > > if ( IO::Socket::INET->new( > > PeerAddr => $target, > > PeerPort => $port, > > Proto => 'tcp', > > Timeout => 1)) { > > print "Port $port is open\n"; > > } > > } > > print "\nPort scan complete\n"; > > exit; > > } > > > > > > Can anyone suggest why I am getting an error and how I can fix it? > > We can try, once you give us a place to start. I already had to do way to > much of your work to determine where the errors arose. FWIW, without strict > compilation, there were no errors. > The messages you got were warnings, telling you that your code was probably > not working [ie that variables were being used without being assigned a > value. > That is a good indication that you should turn strict back on to help find > where the problems are coming from > > Joseph > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > ----------------------------------------- Email provided by http://www.ntlhome.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]