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?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.