There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
calling a perl program from within another perl program


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
csross's Avatar
Member with 93 posts.
 
Join Date: Sep 2004
Experience: Intermediate
30-Nov-2005, 03:19 PM #1
calling a perl program from within another perl program
I have a perl script that reads through a directory and manipulates every mp3. I would like to call another script, passing the name of the mp3 file and returning values obtained in the second program. Then I would like to reference those returned values in the original program.

How do I call the second program, sending it the file to process and leaving place-holders for the return values? This is on a linux server.

Any ideas?
lotuseclat79's Avatar
Distinguished Member with 10,037 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
30-Nov-2005, 03:33 PM #2
Quote:
Originally Posted by csross
I have a perl script that reads through a directory and manipulates every mp3. I would like to call another script, passing the name of the mp3 file and returning values obtained in the second program. Then I would like to reference those returned values in the original program.

How do I call the second program, sending it the file to process and leaving place-holders for the return values? This is on a linux server.

Any ideas?
Hi csross,

You need to make what you call the second program a subroutine and pass it the parameters declared in the first program or main routine. After the subroutine call returns the parameter values, use the names you referred the parameters by in the first routine to continue your computation.

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction between a mere artisan or specialist and a real seeker after truth. - Einstein wrote in 1944.

Some say knowledge is power, I say knowledge without action is powerless. - lotuseclat79

Don't confuse action with movement. - Hemingway to Gardner

Imagination is more important than knowledge. - Einstein
csross's Avatar
Member with 93 posts.
 
Join Date: Sep 2004
Experience: Intermediate
01-Dec-2005, 10:08 AM #3
Hi

Thank you. Unfortunatly I am not a programmer so I do not know the syntax of that. Have you got an example that I could see.

Thanks
lotuseclat79's Avatar
Distinguished Member with 10,037 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
01-Dec-2005, 10:57 AM #4
Quote:
Originally Posted by csross
Hi

Thank you. Unfortunatly I am not a programmer so I do not know the syntax of that. Have you got an example that I could see.

Thanks
Hi csross,

Try this tutorial on Perl: http://archive.ncsa.uiuc.edu/General...ing/PerlIntro/

-- Tom
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
01-Dec-2005, 01:51 PM #5
Quote:
Originally Posted by lotuseclat79
Hi csross,

You need to make what you call the second program a subroutine and pass it the parameters declared in the first program or main routine. After the subroutine call returns the parameter values, use the names you referred the parameters by in the first routine to continue your computation.

-- Tom
Excuse me, this is not correct. The system() function can be used.

Create a string (we can call it "command_string") consisting of the program to be called and its arguments. Then, just:

system( $command_string ) ;
cristobal03's Avatar
Distinguished Member with 2,991 posts.
 
Join Date: Aug 2005
Experience: Advanced
01-Dec-2005, 01:58 PM #6
It's been forever since I used perl, but I'm pretty sure that system returns an integer based on its success. The original poster wants to capture returns, so unless he/she instantiated containers that were passed as references rather than values in the calling procedure, system wouldn't be an effective method for this application.

Nevermind this post if the information is inaccurate.

chris.
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
02-Dec-2005, 09:02 AM #7
If you want to reference an exit status from the called program, system() will return that. If the called program writes the desired value(s) to standard output, you can call the program with back ticks to capture that output. If it's something more complex than this, then making the called program into a subprogram is probably the way to go.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:37 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.