How do I pass values from a .pl to a .pm.

I

Ironhide

With the code below how do I send the value of $value_to_pass to A.pm,
so that sub-routines in A.pm can use them?

A.pm
====

package A;

.....
.....
Do something with the value that I got from the perl script

test.pl
=====
use A;

my $value_to_pass= get_value(...);

sub get_value{
.....
.....
return $value
}

~hanks for your help in advance
_gourab
 
R

RedGrittyBrick

With the code below how do I send the value of $value_to_pass to A.pm,
so that sub-routines in A.pm can use them?

A.pm
====

package A;

....
....
Do something with the value that I got from the perl script

test.pl
=====
use A;

my $value_to_pass= get_value(...);

sub get_value{
....
....
return $value
}

See answers from Henry Law & Tad McClellan

In addition, what you might want to do is make A.pm be object-oriented.
Read `perldoc perltoot`

Then test.pl can do

#!/usr/bin/perl
use strict;
use warnings;
use A;

#
# "send the value of $value_to_pass to A.pm"
#
my $value_to_pass = 42;
my $a = A->new($value_to_pass);

#
# "sub-routines in A.pm can use [it]"
#
$a->foo();
$a->bar();

See the tutorial I referred to for details.
 
J

Jürgen Exner

Ironhide said:
With the code below how do I send the value of $value_to_pass to A.pm,
so that sub-routines in A.pm can use them?

A.pm
====

package A;

....
....
Do something with the value that I got from the perl script

sub Do_something_with_the_value_that_I_got_from_the_perl_script {
my $value = shift;
......
}
 
J

Jürgen Exner

RedGrittyBrick said:
In addition, what you might want to do is make A.pm be object-oriented.

Or at the very least if you prefer a procedural interface have a
function "set()" to not break the data abstraction that the module
provides:

A::set($value_to_pass)

jue
 
C

ccc31807

With the code below how do I send the value of $value_to_pass to A.pm,
so that sub-routines in A.pm can use them?

Why would you want to do that? A module essentially contains common
code that other code can call. For example, if you had a need to
configure the environment for several scripts, say to set $username,
$password, and $ipaddress, so that the script could communicate with
some server, you might want to put the configuration functionality in
a module, like this:

package commoncode;
sub configure
{
my $script = shift;
my %CONFIG;
# open configuration file and set variables
return \%CONFIG;
}

while in your script that needs to be configured, you might do this:

use commoncode;
my $CONFIG = commoncode::configure('FTPscript');
my $username = $CONFIG->{username};
.... and so on.

The point is that your module contains code that you use in your
scripts, and you pass and return values to that code in the same way
you would as if the code were in the script itself.

I may be dumb, dumber, and dumbest, but I can't see how your question
makes any sense.

CC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top