If you want to perl4.pl to take password from perl5.pl, then you should call perl5.pl within perl4.pl rather than calling perl4.pl from perl5.pl.
You have tried to capture line containing "Password" and pass "fred" to STDOUT, though it is incorrect. The actual flow is that system command will be executed first(perl4.pl will execute first) before getting to while loop.
I would suggest you to try the following script if your objective is just to set password from perl5.pl
perl4.pl -
$FileName = "perl5.pl";
-
-
@food = ("pear", "plum", "egg", "apple");
-
$TableLength = $#food;
-
print $TableLength;
-
for($i = 0; $i < $TableLength; ++$i){
-
print "$food[$i]\n";
-
}
-
do{
-
print "Password?\n";
-
$a = `perl $FileName`; # get the output from perl5.pl
-
$a eq "fred" or $a=<STDIN>; ## take STDIN if $a is not "fred"
-
chomp $a;
-
-
}
-
while ($a ne "fred");
-
perl5.pl -
print "fred"; ##pass "fred" or write your code
-
I am using reverse quote instead of system command because, system() will return 0 if the command executed or null if it fails.