Sharmila N babu
Sharmila N babu

Reputation: 1

How to take user input when executing one Perl script from another

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;

When executing test2.pl it doesn't work. How can it be solved?

Upvotes: 0

Views: 83

Answers (1)

mkHun
mkHun

Reputation: 5927

Use require to execute the another program. Try this

test1.pl

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

test2.pl

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

Then easily access the $var from the test1.pl.

Upvotes: 1

Related Questions