Hello all,

I have just started to teach myself perl. I am not completely new to programming, but I would say that I could barely qualify as an intermediate programmer. I've screwed around here and there since I was a kid with Q-Basic, a little origanl visual basic, C++ and python. Though I've never written a program of my own thats, I'd say, prob not more than 100 - 200 lines.

So, I've written this for my first perl learning project

#!/usr/bin/perl use strict; use warnings; sub fib { my $n = shift; return $n if $n < 2; return fib($n - 1) + fib($n - 2); } my $value = 0; my $range = 0; my $phiApprox = 0; my $i = 0; my $temp = 0; my $fibValue1 = 0; my $fibValue2 = 0; print "Fibonnaci Fun\n\n"; print "Pick a number that represents which value of the Fibonnaci sequ +ence you want to start with\n"; print "ie: 1 would be 1 and 2 would 1 and 3 would be 2 and so on.\n"; print "Your choice: "; chomp($value = <>); print "\nNow pick a number to repesent the range you want.\n"; print "If you want to use values 1 through 10 you you need only enter +10,\n"; print "assuming of course you entered 1 above.\n"; print "Your choice: "; chomp($temp = <>); $range = $value + $temp; for($i = $value; $i <= $range; $i++){ $fibValue1 = fib($i); $fibValue2 = fib($i - 1); if($i <= 1){$phiApprox = 0}; if($i >= 2){$phiApprox = $fibValue1 / $fibValue2}; print "\n"; print $fibValue1.' / '.$fibValue2.' = '.$phiApprox; } print "\n";

I was just wondering, for learning purposes, if there was something that could been done to speed up the program. Not that i expect to it run real fast at all, I know I'm dealing with large numbers. I am just wondering if there is any function or something that could speed up how perl handles larger numbers.

I would also appreciate any constructive criticism on my code, I am here to learn.

As I am knew here I hope I've done nothing wrong in formating and placing this post, and apologies in advance if I have


In reply to how to speed up program dealing with large numbers? by Solarplight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.