When test-running one of my perl scripts, I encountered something very strange.
The main file requires two other scripts. The first two lines under the #! are require statements. Like so
Both of the scripts only have functions that are to be called by the main program. When the function call is encountered by the main script, it doesn't call the function.Code:#!/usr/bin/perl require "IOcontrolAlg.pl"; require "FuncList.pl"; . . . .
In pseudo-code, it looks slightly like this:
Code:#!/usr/bin/perl require "funclist.pl" while ($input = <SDTIN>){ chomp($input); if ($input eq "test1\"){ function1; #where function1 is a function in 'funclist.pl' } else { function2; #where function2 is a function in 'funclist.pl' } }
Programming is an art form. Everyone can program, but few can do it right.
It should work. If it doesn't work you should post any error messages you are getting. If the code is not too long you can also post the code.
There is no error, but the main perl script is not calling any of the functions in the other scripts.
code for the main file:
The scripts together will make a calculator, where 'IOcontrol.pl' parses what the user types in (such as "56+24" or "cos(56.326)"), making sure it's valid, then figures out what function in 'Mathfunc.pl'.Code:#!/usr/bin/perl #the main files used require "Mathfunc.pl"; require "IOcontrol.pl"; print <<STARTUP; /////////////////////////////////////// /Command Line Calculator (version 0.0)/ / / /If you are new, type in 'help'. / / / /For version history, type in 'ver'. / / / /To continue on, type in 'calc'. / / ///////////////////////////////////// STARTUP $lobby = 1; #just to control flow while ($lobby == 1){ $input = <STDIN>; chomp($input); if ($input eq "help"){ helpfile; #where this is a function in another file } elsif ($input eq "ver"){ version; #where this is a function in another file } elsif ($input eq "calc"){ $lobby = 0; } else { print "unrecognized command\n"; } } . . . . .
I managed my way around '@inc', but when I type something in at the start, like 'help', it just sits there, not doing a thing.
Programming is an art form. Everyone can program, but few can do it right.
Turn on warnings (-w):
#!/usr/bin/perl -w
#the main files used
require "Mathfunc.pl";
require "IOcontrol.pl";
that will warn of any problems in the main script or any of the required scripts. Retry the code with warnings on and see if you get any warnings.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks