Problem in passing values to perl script using another perl script

Discussion in 'Perl Misc' started by vikrant, Aug 10, 2005.

  1. vikrant

    vikrant Guest

    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
    vikrant, Aug 10, 2005
    #1
    1. Advertising

  2. vikrant wrote:
    > 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().

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Aug 10, 2005
    #2
    1. Advertising

  3. vikrant

    Joe Smith Guest

    vikrant wrote:

    > #!/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
    Joe Smith, Aug 10, 2005
    #3
  4. vikrant

    vikrant Guest

    Thanks for the information.

    Vikrant
    vikrant, Aug 10, 2005
    #4
  5. vikrant

    Guest

    vikrant <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Aug 10, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,492
    BobMonk
    Jul 15, 2003
  2. Mike Wimpe
    Replies:
    1
    Views:
    384
    Fuzzyman
    Mar 14, 2005
  3. Andy B.
    Replies:
    7
    Views:
    2,886
    Steve S
    Dec 27, 2008
  4. Robert Cohen
    Replies:
    3
    Views:
    246
    Andrew Durstewitz
    Jul 15, 2003
  5. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    119
    Paul Lalli
    Jan 5, 2005
Loading...

Share This Page