LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   perl recursion (https://www.linuxquestions.org/questions/linux-newbie-8/perl-recursion-619035/)

sharath.bv 02-06-2008 03:54 AM

perl recursion
 
Hi all,

Does perl supports recursive function calls ? :study:

acid_kewpie 02-06-2008 04:00 AM

yes, but it's not really something that is "supported". Recursion is just a way of coding, not a function that is provided in itself. if you can call a function at all, you could recurse through it. unless your language of choice is extremely bizarre, or not procedural. even functional languages like ml will still have the ability to recurse afaik.

sharath.bv 02-08-2008 03:26 AM

Hi all,

i have a problem while performing recursion......

-------------------------------------------------
func()
{
open(INPUT,file_name) --------> "file_name is provided by user"
while(<INPUT>)
{
....perform comutation here.........
....................................
if (condition)
{
funct() ->------> #whenever control comes after last visiting this functions
#it displays a message saying "readline() on closed
# filehandle INPUT on file_name at ** line.
}
}
close(INPUT);
}
----------------------------------------------------

Matir 02-08-2008 07:21 AM

Probably because the recursive call closed the file, so when it returns to the outer call and it tries to read again, it discovers the file is closed. You may want to move the open/close outside the recursively-called function.


All times are GMT -5. The time now is 08:45 AM.