problem in passing parameters in function defined in perl module

Discussion in 'Perl Misc' started by Sherm Pendley, Jun 29, 2005.

  1. Re: problem in passing parameters in function defined in perlmodule

    Vikrant <> writes:

    > 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--

    --
    Due to the amount of unreadable gibberish being posted from Google Groups,
    I seldom read messages posted from there.

    Cocoa/Perl: http://camelbones.sf.net Hire Me: http://www.dot-app.org
    Sherm Pendley, Jun 29, 2005
    #1
    1. Advertising

  2. Sherm Pendley

    Vikrant Guest

    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
    Vikrant, Jun 29, 2005
    #2
    1. Advertising

  3. Vikrant wrote:
    > 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
    Jürgen Exner, Jun 29, 2005
    #3
  4. Re: problem in passing parameters in function defined in perlmodule

    Gunnar Hjalmarsson <> writes:

    > Vikrant wrote:


    >> sub Configure($ddd)
    >> {
    >> print"$ddd";
    >> }

    >
    > 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--

    --
    Due to the amount of unreadable gibberish being posted from Google Groups,
    I seldom read messages posted from there.

    Cocoa/Perl: http://camelbones.sf.net Hire Me: http://www.dot-app.org
    Sherm Pendley, Jun 29, 2005
    #4
  5. Vikrant wrote:
    > 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

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jun 29, 2005
    #5
  6. Sherm Pendley

    Vikrant Guest

    Thanks for the info . i have just started off with the perl.

    vikrant
    Vikrant, Jun 29, 2005
    #6
  7. Sherm Pendley

    Vikrant Guest

    Sherm Pendley wrote:
    >
    > 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
    Vikrant, Jul 1, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oodini
    Replies:
    1
    Views:
    1,734
    Keith Thompson
    Sep 27, 2005
  2. Floris Bruynooghe
    Replies:
    1
    Views:
    323
    Floris Bruynooghe
    Dec 24, 2008
  3. Ramon F Herrera
    Replies:
    8
    Views:
    457
    Pascal J. Bourguignon
    Sep 13, 2009
  4. Alok
    Replies:
    3
    Views:
    233
  5. Replies:
    6
    Views:
    342
    Eric Sosman
    Oct 24, 2012
Loading...

Share This Page