0

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?

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by bryansmith123
0

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.

0

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.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.