Call perl script with a variable

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 17
Reputation: yair7190 is an unknown quantity at this point 
Solved Threads: 0
yair7190 yair7190 is offline Offline
Newbie Poster

Call perl script with a variable

 
0
  #1
Nov 21st, 2008
Although it sounds pretty simple, i haven't found a proper answer for this issue.

I want to know how can i call a perl script and pass a variable to it.
For example, lets say "Parse.pl" is a parsing script of some sort and i want to call it from another perl script, or from a command line, with a variable: Parse($line);
Parse.pl will get the variable $line, perform parsing on it and return it to the main script (the return part is not really important);

Any idea how its done?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Call perl script with a variable

 
0
  #2
Nov 25th, 2008
Hi,
I would recommend you to define a method in Parse.pl and use it in your client script which requires parsing. For eg.
#caller.pl
require 'Parse.pl';
#...
# call method parse_me(for eg.) in Parse.pl
my $return_val = Parse::parse_me($line);
#...
#Parse.pl
sub parse_me{
my $line = @_;
#...
}
1;
Note: In Parse.pl define only methods, because when you require something, perl will try to execute that script first and then subsequent lines following require line.

hope this helps.

katharnakh.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 147
Reputation: GDICommander is an unknown quantity at this point 
Solved Threads: 19
GDICommander's Avatar
GDICommander GDICommander is offline Offline
Junior Poster

Re: Call perl script with a variable

 
0
  #3
Feb 6th, 2009
You can use Getopt. Here is the link:

http://perldoc.perl.org/Getopt/Long.html
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 10
Reputation: bryansmith123 is an unknown quantity at this point 
Solved Threads: 0
bryansmith123 bryansmith123 is offline Offline
Newbie Poster

Re: Call perl script with a variable

 
0
  #4
Feb 20th, 2009
Originally Posted by yair7190 View Post
Although it sounds pretty simple, i haven't found a proper answer for this issue.

I want to know how can i call a perl script and pass a variable to it.
For example, lets say "Parse.pl" is a parsing script of some sort and i want to call it from another perl script, or from a command line, with a variable: Parse($line);
Parse.pl will get the variable $line, perform parsing on it and return it to the main script (the return part is not really important);

Any idea how its done?
If you execute your script at ~>Parse.pl a b c
you get the command line values in the @ARGV array which you can run through in a loop.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC