Hey guys – I’m wondering if I can get a little help here. I’m, decent with Perl but seem to have stumbled into something above my knowledge level.

I have a proprietary application that can test traffic on different network ports. So, it works like this: `call application (SOURCE IP) (DEST IP):(PORT)` (Basically, just like nc without the source)

There are a number of different values for each of the above parameters. So, I want to build a simple menu to allow an operator to answer applicable questions and build the appropriate command – not too hard right? I’ve already done the same thing in Bash, but the Bash script is so slow that I set out to do it in Perl instead and I’ve hit a roadblock that I can’t get by for 3 days now.

Everything else below is the same with different variable names, before

&menu($menu1); System(application $SOURCE $DEST:$PORT) ;

I’m trying to pass an argument in when option 1 is selected and use to call an element in each array – but because it all executes at runtime – no matter which option is selected in the menu, the last entry in every array is the result.

So, I’ve been through several iterations of passing an argument in when the sub is called – but that’s going nowhere. I think it’s because of the runtime issue. Basically, it seems to me like what I’m trying to do can’t be done with the menu method above – but there has to be a way to do this very simply idea right?

I have got it to work by calling a unique sub for each choice in the menu, as that way I don’t have to pass anything and each sub can be dedicated to whatever value I want. But, I have a total of 35 different options of the @PORT array alone; I really don’t want to have to do 50 some odd subs – however, that does work.

Nearly every thread in this forum encourages programmers to always use strict and warnings. Your code tries to use bare words and symbolic references, neither of which are allowed under strict.

Place the following at the start of your script:

Code

use strict; use warnings;

Fix all the errors and warnings which perl reports. There is a fair chance you can fix your problem yourself. If not, post code that we can actually run and duplicate the problem (and verify any solution we may propose). Good Luck, Bill

Re: [BillKSmith] Pass Aurgment When sub is called in menu
[In reply to]

Can't Post

OK thanks - I'll check those links out

BTW - I am using strict and warnings - I just don't have my code on the Internet equipped system and can't get it over there - so I just banged out a quick once-over of what I was doing in a Word doc and posted it.

As soon as I succeeded in correcting all the errors that perl reported, your code worked the way I think you intend. If you had done what FishMonger and I requested, you would have solved the problem yourself.

What made you think your code did not work right. You could not possibly have run it with that many syntax errors.

This version is much shorter than yours. It has better error handling and it is easier to understand. Readonly is not required. I have used it only to tell the reader that these "variables" never change.

You probably want to make changes. Go ahead. My objective was to make that as easy as possible. Good Luck, Bill

Re: [FishMonger] Pass Aurgment When sub is called in menu
[In reply to]

Can't Post

I intentionally kept that example to its minimum to show how easy and clean it could be with a proper module. Your code used numbers for selecting menu items and that could easily be done in the code I used by adding the -i option parameter the the prompt calls.

If your menu choices are limited, then hard coding them in the script is fine, but if you have a lot of items, it would be best to have them in a config file (such as an ini file) or in a database and retrieve them as needed.

It is of course better to install a module with the right installation tools provided with the module, but if you can't do it the standard way, the IO::Prompter module is, if I am not wrong, a Perl-only module. At the very least, you should be able to install it just in the same way as you will install your own program (i.e. copy it to the right directory). You'll probably have a couple of dependencies to handle, but it should still be quite easy.