Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > calling subroutine

Reply
Thread Tools

calling subroutine

 
 
Madhu Ramachandran
Guest
Posts: n/a
 
      01-03-2006
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


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-04-2006
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
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      01-04-2006
Madhu Ramachandran <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Madhu Ramachandran
Guest
Posts: n/a
 
      01-04-2006
did stupid mistake.. typo in calling place.

sorry for wasting all your times.
"Tad McClellan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Madhu Ramachandran <(E-Mail Removed)> 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
> (E-Mail Removed) Perl programming
> Fort Worth, Texas



 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      01-04-2006
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.

 
Reply With Quote
 
Eric Bohlman
Guest
Posts: n/a
 
      01-05-2006
Gunnar Hjalmarsson <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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.
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-05-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Calling another subroutine sck10 ASP .Net 3 08-15-2005 05:27 PM
Calling subroutine in fortran module Amit C Programming 5 02-07-2005 06:55 AM
Calling fortran subroutine from c Bigdakine C Programming 13 09-25-2004 08:12 AM
Calling ASP.NET server side subroutine from javascript asadikhan ASP .Net 2 04-25-2004 07:51 AM



Advertisments