Teen Programmers Unite  
 

 

Return to forum top

How do i code to run second perl file when i run the first perl file?

Posted by Perl [send private reply] at February 06, 2003, 10:08:20 PM

hi...i think i have solve the socket problem...but there is another problem..
here is the problem, how do i code to run (not open file()) a second perl file inside the first perl file when i run the first perl file?? it is something like system() or sysopen()???`


anyone know??...thanks

Posted by gian [send private reply] at February 07, 2003, 01:01:38 AM

I imagine there is some sort of include() or require() functions as there are in PHP, but system("perl something.pl") should work too.

Posted by Perl [send private reply] at February 07, 2003, 01:28:40 AM

thanks...i kept using system(something.pl) without the perl in front of it...really thanks..

Posted by buzgub [send private reply] at February 07, 2003, 01:39:24 AM

The problem with system(something.pl) is that something.pl is a string, and so needs to be surrounded by quotes, like so: "something.pl"

Posted by Perl [send private reply] at February 07, 2003, 01:46:20 AM

ya..thats right!!

system("perl $command");

1)but is it a bad way???

2)but by using system call..the second pl file will overwrite the first pl file...

can i make the second pl file to run separately but the second pl file is sill call by the first pl file???

Posted by buzgub [send private reply] at February 07, 2003, 02:12:31 AM

What do you mean by overwrite? When you use the system function, the execution of the program doing the calling will stop, the called program will start, and once the called program finishes the calling program will continue. The exec call will overwrite your program - the program that calls exec will stop and be replaced by the program specified in the call. If you want both of the programs to be running at the same time, you need to look at the fork system call.

Posted by Perl [send private reply] at February 07, 2003, 02:15:57 AM

wow..cool!!..this is useful!

but are there any links where i can see real coding stuffs???

Posted by Perl [send private reply] at February 07, 2003, 02:30:20 AM

the overwrite means the first pl file (calling program) will stop and wait for the second pl file (called program)to run but the second pl file(called program) will hang there..without returning the control to the first pl file(calling program)..

Posted by Perl [send private reply] at February 07, 2003, 02:52:54 AM

hmmm...one more question..when my first pl file(calling program) call and run the second pl file(called program)...am i able to display the results to my first pl file(calling file)??? possible??

Posted by buzgub [send private reply] at February 07, 2003, 03:23:47 AM

First off: does your second program work fine when you run it in isolation? It needs to.

To get the output of the second program into the first, you should look into using open commands like this one:
open CONTROL, "program2.pl|"

You can see an explanation of that at http://www.rocketaware.com/perl/perlfunc/open.htm

I consider everything I've told you so far to be "real coding stuff." If by that you mean examples you should use a search engine to try to find pages about what interests you.

Posted by Perl [send private reply] at February 09, 2003, 10:08:03 PM

Is that for UNIX-based platform??
i'm running under the DOS-based platform!

Posted by buzgub [send private reply] at February 10, 2003, 04:24:24 AM

Everything I've said here applies to windows based perl installations, as well as unix ones. Only the fork system call is likely to be problematic under DOS, but you wouldn't have networking there anyway :)

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.