Re-entrant code ???

T

tyjb

I'm new to Windows perl and am recreating a menuing system that we
have on Unix, perl calling perl using the do command. The menus
present options to users with some options going to other menus. When
I execute one of the options, not another menu, I use "return" to
return to the calling menu/program. When I do, all numeric inputs
from the user are ignored. The only valid input is an "e" which exits
the menu. Any idea what's happening? Below is the code that returns
the program to the calling program.

if ($length == 0) {
print "Job $job currently has no output to display\n";
sleep 3;
return; }
 
P

Paul Lalli

I'm new to Windows perl and am recreating a menuing system that we
have on Unix, perl calling perl using the do command. The menus
present options to users with some options going to other menus. When
I execute one of the options, not another menu, I use "return" to
return to the calling menu/program. When I do, all numeric inputs
from the user are ignored. The only valid input is an "e" which exits
the menu. Any idea what's happening? Below is the code that returns
the program to the calling program.

if ($length == 0) {
print "Job $job currently has no output to display\n";
sleep 3;
return; }

Please post a short BUT COMPLETE program that demonstrates what the
heck you're talking about.

This and other good advice can be found in the Posting Guidelines for
this group, posted here twice weekly.

Paul Lalli
 
T

tyjb

Please post a short BUT COMPLETE program that demonstrates what the
heck you're talking about.

This and other good advice can be found in the Posting Guidelines for
this group, posted here twice weekly.

Paul Lalli

Here's how the parent calls the child:

chomp($input = <STDIN>); if ($input eq "1") {
$load_cmd = "perl -w \\\\tlrntfs1\\IT_Common\\PMT\\jobs\\ojob.pl";
system("$load_cmd");

Here's the child returning to the parent:

while (true) {
system(($^O eq 'MSWin32') ? 'cls' : 'clear'); print
"********************************************************\n";
print "**************** DISPLAY ACTIVITY **********************\n";
print "*********( Auto Cycles Every 5 seconds )****************\n";
print "********************************************************\n";
print " \n";
($sec, $min, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
$dayOfYear, undef) = localtime();
$mins = sprintf "%02u", $min;
$hours = sprintf "%02u", $hour;
$secs = sprintf "%02u", $sec;
$string = "Current Date & Time: $weekDays[$dayOfWeek] $months[$month]
$dayOfMonth, $year $hours:$mins:$secs Central\n";
print "$string\n";
print " \n";
@array = glob("*");
foreach $filex (@array) {
open(INFO, $filex); @lines = <INFO>;
close(INFO); print @lines; }
print " \n";
print " \n";
print "************>>>>> to quit, do a Control / C\n";
$SIG{INT} = sub{&create_break};
if ($a_ok == $nah) {
$input = "";
return; }
sleep 5
}

sub create_break {
$a_ok = $nah; }
 
P

Paul Lalli

Here's how the parent calls the child:

Which part of "complete" confused you?

Nothing in anything you posted shows how the child is supposedly
passing input back to the parent. Nothing in anything you posted
shows the supposed do{} command that's calling a child. Nothing in
anything you posted is reading data from the user.

Pare your problem down to the SHORTEST COMPLETE script that still
exhibits the problem. And then post that.

It's also fairly apparent from the code you posted that you're using
neither strict nor warnings. Start using both. They find 95% of the
errors you're likely to make.

Paul Lalli
 
J

Joe Smith

tyjb said:
system("perl ojob.pl");

The system() call returns a single value: 0 for success and nonzero if
the other program returned some sort of error.

When ojob.pl invoked via system(), it can _NOT_ affect any variables in the
parent program. That's not how values are passed from one script to another.

Looks to me that you haven't learned the difference between

$string_value = `perl ojob.pl`;
@array_values = `perl ojob.pl`;
$error_code = system 'perl ojob.pl';
and
@data = do "ojob.pl";

Look into "do" and how to use modules.

-Joe
 
J

Jürgen Exner

Joe said:
The system() call returns a single value: 0 for success and nonzero if
the other program returned some sort of error.

You are greatly mistaken. I suggest you re-read the third paragraph of the
documentation of system().
When ojob.pl invoked via system(), it can _NOT_ affect any variables
in the parent program. That's not how values are passed from one
script to another.

This of course is quite true.

jue
 
J

Joe Smith

Jürgen Exner said:
You are greatly mistaken. I suggest you re-read the third paragraph of the
documentation of system().

The point I was making is that it returns a single value.

You're right; I should not have implied that a nonzero exit code
or signal indicates an error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top