problem in passing parameters in function defined in perl module

S

Sherm Pendley

Vikrant said:
sub Configure($ddd)
{
print"$ddd";
}

$ddd is not doing what you think it's doing. Subroutine prototypes in Perl
are used very rarely, and even then only declare types, not names. Arguments
are always passed in @_.

With that in mind:

# Unrelated parts of sample1.pm omitted...

our @EXPORT=qw(Configure);

sub Configure {
my $ddd = shift;
print $ddd;
}

Have a look at:
perldoc perlsub
perldoc -q always

sherm--
 
V

Vikrant

hi
i have problem is passing variable of a sample.pl file as a parameters
to a function defined in sample1.pm.

for example

sample.pl
*******************************************
#!usr/bin/perl
use sample1;
$dd=100;
sample1->Configure($dd);
*******************************************

and sample1.pm
*****************************************
#!usr/bin/perl
package sample1;
use Exporter;
our @ISA=qw(Exporter);
our @EXPORT=qw(Configure($ddd));

sub Configure($ddd)
{
print"$ddd";
}
****************************************
Both are in same directory but running sample.pl does not give any output.

regards
 
J

Jürgen Exner

Vikrant said:
i have problem is passing variable of a sample.pl file as a
parameters to a function defined in sample1.pm.

for example [...]
package sample1;

If you had used warnings and strictures then perl would have told you what
is wrong.

[...]
sub Configure($ddd)

No idea what this is supposed to do but most likely it doesn't do what you
think it is doing.
In Perl function arguments can be accessed in @_, not in named variable like
that. Too much Pascal/Modula programming recently?
{
print"$ddd";

print $_[1];
Oh, and also a useless use of quote.

jue
 
S

Sherm Pendley

Gunnar Hjalmarsson said:
Vikrant wrote:

Sorry, but I don't understand how you are thinking now.

He's probably accustomed to C, Java, Pascal, or some other language where
arguments are named and their names declared with the function prototype. For
instance, in C:

void Configure(int ddd) {
...
}

sherm--
 
G

Gunnar Hjalmarsson

Vikrant said:
i have problem is passing variable of a sample.pl file as a parameters
to a function defined in sample1.pm.

for example

sample.pl
*******************************************
#!usr/bin/perl
use sample1;
$dd=100;
sample1->Configure($dd);

You mean

Configure($dd);

don't you?
and sample1.pm
*****************************************
#!usr/bin/perl
package sample1;
use Exporter;
our @ISA=qw(Exporter);
our @EXPORT=qw(Configure($ddd));

How does that $ddd variable come in? If you want to export the
'Configure' symbol, just say:

our @EXPORT=qw(Configure);
sub Configure($ddd)
{
print"$ddd";
}

Sorry, but I don't understand how you are thinking now. In my world, the
sub should look something like:

sub Configure { print shift, "\n" }

HTH
 
V

Vikrant

Sherm said:
He's probably accustomed to C, Java, Pascal, or some other language where
arguments are named and their names declared with the function prototype. For
instance, in C:

void Configure(int ddd) {
...
}

Actually yes, I am accustomed to C style coding, and that is what was
baffling me. Thanks all for your help once again.

Vikrant
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top