The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calling sed problem!! andy2000 Shell Programming and Scripting 1 05-02-2007 10:38 AM
Problem while calling Oracle 10g SQLPLUS files ganapati UNIX for Advanced & Expert Users 2 05-01-2007 12:03 AM
chpass subroutine not updating NIS rmm47 High Level Programming 1 03-30-2007 07:30 AM
shell script calling problem dhananjaysk Shell Programming and Scripting 2 03-30-2006 07:48 AM
how to write stderr in a subroutine log file?.. sekar sundaram Shell Programming and Scripting 1 11-24-2005 06:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-16-2006
Registered User
 

Join Date: Aug 2005
Posts: 45
Problem in subroutine calling

Hi,
we can call the subroutines using two ways ....
1) calling subroutine name preceeded by & symbol.
2)Another one is without &symbol....
what is the diff b/w these two....
############################
#usr/bin/perl
fun;
sub fun
{
print "hi this is from perl\n";
}
############################
the above code is doesn't worked for me...... if i called like fun;
but i changed the subroutine call like this &fun;
then it works .............plz tell me what is happenning here.
In my project script, they called the subroutines either way....in that it works..........i tried this small experiment it doesn't worked.....plz help me out.
Thanks in advace...
Sarwan.
Reply With Quote
Forum Sponsor
  #2  
Old 01-16-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Very simply put, if you have the subroutine definition before the actual invocation, then you can call the subroutine as is i.e. without the ampersand. The subroutine acts like a builtin, in this case.

In case its the other way round, i.e. invocation comes first, and then the definition, you would need the ampersand to let perl know that you are refering to the subroutine defined later.

There are other instances where you cannot avoid the & way of invoking subroutines.

See the Oreilly sample chapter - Subroutines
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0