![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |