Как да вземете информация от потребителя, когато изпълнявате един Perl скрипт от друг

test1.pl

#! /usr/bin/perl
print "enter the user data";
$var=<>;
print "the entered data:$var";

test2.pl

#! usr\bin\perl
$var=`test2.pl`;
print $var;

При изпълнение на test2.pl не работи. Как може да се реши?


person Sharmila N babu    schedule 21.08.2015    source източник
comment
Обаждате се на test2.pl в test2.pl, защо? Какво очакваш от test2.pl?   -  person serenesat    schedule 21.08.2015


Отговори (1)


Използвайте require, за да изпълните друга програма. Опитайте тази

test1.pl

print "enter the user data ";
chomp($var=<>);
print "the entered data:$var\n";

test2.pl

require "test1.pl";
print "$var\n";

След това лесно достъпете $var от test1.pl.

person mkHun    schedule 21.08.2015