calling subroutine

  • Thread starter Madhu Ramachandran
  • Start date
M

Madhu Ramachandran

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
 
G

Gunnar Hjalmarsson

Madhu said:
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

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

Tad McClellan

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

Madhu Ramachandran

did stupid mistake.. typo in calling place.

sorry for wasting all your times.
 
E

Eric Bohlman

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

Gunnar Hjalmarsson

Eric said:
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. :)
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top