Problem in passing values to perl script using another perl script

V

vikrant

hi

i have two perl scripts user.pl and user_database.pl

user.pl #script store in /home/bob directory
--------------------------------
#!/usr/bin/perl
print"Enter the user name";
$name = <STDIN>;
print "$name";
----------------------------------


user_database.pl # script store in /home/bob directory
----------------------------------
#!/usr/bin/perl
$user_name = "BOB";

system("perl /home/bob/user.pl");

--------------------------------
# output after running user_database.pl

Enter the user name

It asked me to enter user name. Now,i have to enter the value using my
keyboard but i do not want to do so.

i want that the value of "$user_name" pass to this automatically.

But,i am not able to do so.

Due to some reason i do not want to make use of command line arguments.

Actullay,I am new to perl so please let me know if am missing something.



With Regards
Vikrant
 
G

Gunnar Hjalmarsson

vikrant said:
i have two perl scripts user.pl and user_database.pl

user.pl #script store in /home/bob directory
--------------------------------
#!/usr/bin/perl
print"Enter the user name";
$name = <STDIN>;
print "$name";
----------------------------------


user_database.pl # script store in /home/bob directory
----------------------------------
#!/usr/bin/perl
$user_name = "BOB";

system("perl /home/bob/user.pl");

--------------------------------
# output after running user_database.pl

Enter the user name

It asked me to enter user name. Now,i have to enter the value using my
keyboard but i do not want to do so.

i want that the value of "$user_name" pass to this automatically.

Then make use of the @ARGV variable and don't fork a new process, i.e.
use do() or require() instead of system().
 
J

Joe Smith

vikrant said:
#!/usr/bin/perl
$user_name = "BOB";

system("perl /home/bob/user.pl");

$user_name = 'BOB';
open my $pipe,'|-','perl /home/bob/user.pl'
or die "Could not open pipe: $!";
print $pipe $user_name,"\n";
close $pipe or warn "Problems on pipe close: $!";

This is assuming you really have a need for executing user.pl
as a separate process, as opposed to using
use '/home/bob/user.pl';
or
require '/home/bob/user.pl';


-Joe
 
X

xhoster

vikrant said:
hi

i have two perl scripts user.pl and user_database.pl

user.pl #script store in /home/bob directory
--------------------------------
#!/usr/bin/perl
print"Enter the user name";
$name = <STDIN>;
print "$name";
----------------------------------

user_database.pl # script store in /home/bob directory
----------------------------------
#!/usr/bin/perl
$user_name = "BOB";

system("perl /home/bob/user.pl");

$user_name = "BOB";
warn "This is probably a stupid way to solve whatever your root problem
is"; system("echo $user_name | perl /home/bob/user.pl")

It asked me to enter user name. Now,i have to enter the value using my
keyboard but i do not want to do so.

i want that the value of "$user_name" pass to this automatically.

But,i am not able to do so.

Due to some reason i do not want to make use of command line arguments.

If you are not able to do things in the most appropriate manner due to some
bizarre reason, and you fail to explain what that bizarre reason is, how
are we supposed to help circumvent that bizarre limitation? Any solution
we propose from out of the darkness is also likely to run afoul of the same
bizarre, unexplained reason that prevents you from doing it right in the
first place.

(But in this case, "doing it right" is at least as likely to be modules,
rather than command line arguments in a system call.)

Xho
 

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

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top