calling subroutine

Discussion in 'Perl Misc' started by Madhu Ramachandran, Jan 3, 2006.

  1. hi,

    iam new to perl. Iam getting an error in a subroutine invocation.

    I have a main perl script say main.pl
    I have a doThis.pl perl script in scripts subdir. So in main.pl i have the
    following

    #file: main.pl
    #!/usr/local/bin/perl

    unshift(@INC, "./scripts);
    require("common.pl");
    &common_sub(); # this is in common.pl file in scripts subdir
    system("scripts/doThis.pl");
    ##### end of main.pl ####

    #File: scripts/doThis.pl
    #!/usr/local/bin/perl

    print ("Hello there\n");
    &mysub();

    sub mysub()
    {
    print ("in mysub\n");
    }
    #### end of doThis.pl

    I get error when i run
    #perl main.pl
    Undefined subroutine &main::mysub called at scripts/doThis.pl line 4,
    <STDIN> line 1.

    If i take out the unshift() and require in main.pl, and also take out the
    call to common_sub, then
    there is no error in call to mysub() in doThis.pl

    would appreciate any help.
    Thanks.

    Madhu
    Madhu Ramachandran, Jan 3, 2006
    #1
    1. Advertising

  2. Madhu Ramachandran wrote:
    > hi,
    >
    > iam new to perl.


    Then I can't help asking from where you got that programming style. It's
    very old, and should not be used in a Perl program of 2006.

    Please study some tutorial or book from this millenium.
    http://learn.perl.org/

    > Iam getting an error in a subroutine invocation.
    >
    > I have a main perl script say main.pl
    > I have a doThis.pl perl script in scripts subdir. So in main.pl i have the
    > following


    <scripts snipped>

    > I get error when i run
    > #perl main.pl
    > Undefined subroutine &main::mysub called at scripts/doThis.pl line 4,
    > <STDIN> line 1.


    When I tried your code, it didn't compile... After a couple of
    corrections, I couldn't reproduce the error.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jan 4, 2006
    #2
    1. Advertising

  3. Madhu Ramachandran <> wrote:


    > unshift(@INC, "./scripts);

    ^
    ^ where's the other quote?


    > I get error when i run
    > #perl main.pl
    > Undefined subroutine &main::mysub called at scripts/doThis.pl line 4,



    Funny, I get a different message when I run your program.


    > would appreciate any help.



    Would appreciate if you posted Real Perl Code.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 4, 2006
    #3
  4. did stupid mistake.. typo in calling place.

    sorry for wasting all your times.
    "Tad McClellan" <> wrote in message
    news:...
    > Madhu Ramachandran <> wrote:
    >
    >
    >> unshift(@INC, "./scripts);

    > ^
    > ^ where's the other quote?
    >
    >
    >> I get error when i run
    >> #perl main.pl
    >> Undefined subroutine &main::mysub called at scripts/doThis.pl line 4,

    >
    >
    > Funny, I get a different message when I run your program.
    >
    >
    >> would appreciate any help.

    >
    >
    > Would appreciate if you posted Real Perl Code.
    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas
    Madhu Ramachandran, Jan 4, 2006
    #4
  5. Madhu Ramachandran

    Joe Smith Guest

    Madhu Ramachandran wrote:
    > did stupid mistake.. typo in calling place.


    That's why you should always copy-and-paste the code in
    question; don't re-type it.
    Joe Smith, Jan 4, 2006
    #5
  6. Madhu Ramachandran

    Eric Bohlman Guest

    Gunnar Hjalmarsson <> wrote in
    news::

    > Please study some tutorial or book from this millenium.


    I think you meant "millennium," which has two n's because it comes from the
    Latin root _annus_ (year) which also has two n's. "Millenium" comes from a
    different Latin root (which, as you might expect, has only one n), and
    although it represents a useful concept (see
    http://www.ratbags.com/rsoles/) it's not particularly applicable here. Or
    maybe it is; there are a fair number of Perl tutorials and books whose
    quality is so low that they must have been produced by a millenium.
    Eric Bohlman, Jan 5, 2006
    #6
  7. Eric Bohlman wrote:
    > Gunnar Hjalmarsson wrote:
    >>Please study some tutorial or book from this millenium.

    >
    > I think you meant "millennium," which has two n's because it comes from the
    > Latin root _annus_ (year) which also has two n's. "Millenium" comes from a
    > different Latin root (which, as you might expect, has only one n), and
    > although it represents a useful concept (see
    > http://www.ratbags.com/rsoles/) it's not particularly applicable here. Or
    > maybe it is; there are a fair number of Perl tutorials and books whose
    > quality is so low that they must have been produced by a millenium.


    Thanks for the correction and the link. :)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jan 5, 2006
    #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. asadikhan
    Replies:
    2
    Views:
    3,652
    =?Utf-8?B?SG1udA==?=
    Apr 25, 2004
  2. sck10

    Calling another subroutine

    sck10, Aug 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    449
    =?Utf-8?B?U3JlZWppdGggUmFt?=
    Aug 15, 2005
  3. Bigdakine

    Calling fortran subroutine from c

    Bigdakine, Sep 1, 2004, in forum: C Programming
    Replies:
    13
    Views:
    645
    Mark L Pappin
    Sep 25, 2004
  4. Amit

    Calling subroutine in fortran module

    Amit, Jan 30, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,597
    Dave Thompson
    Feb 7, 2005
  5. king
    Replies:
    5
    Views:
    173
Loading...

Share This Page