title: fibonacci series in perl executes to infinite loop
body: <p>Hi I am trying to execute fibonacci series with recursive function using perl. This is the code  </p>
  
  <pre><code>#! /user/bin/perl
  
  print "enter the number of elements for the series\n";
  $value=&lt;stdin&gt;;
  chomp($value);
  print "\n\nThe value entered is $value\n\n";
  for($i=0;$i&lt;$value;$i++)
  {
      print "fib($i)=".&amp;fib($i);
      print "\n";
  }
  
  
  sub fib
  {
      $rec=@_[0];
  
      print"In the subroutine rec is :".$rec."\n";
      if($rec == '0')
      {
          $f='0';
      }
      if($rec == '1')
      {
          $f='1';
      }
      else
      {
          $f=fib($rec-1)+fib($rec-2);
      }
  
      return $f;
  }  
  </code></pre>
  
  <p>But this code ends up in an infinite loop. Can anyone help with the mistake i have made.</p>