Hey monks,

So I want to be able to find the dividend from a stock. I've managed to do it in a simple way, but this time, I want to do it using a recursive routine. I can't seem to figure out how to do this. But anyway, here's the original script along with a few miserable attempts.

use warnings; print "A stock xyz's price is now $100. It has 3.78% dividend. You hav +e 1000 of it and reinvest the dividend into the stock.\n"; my %hash; @stocknum = 1000; @dividend = 6780; while ($#dividend != 20) { $a = $dividend[-1]; $stock = $stocknum[-1]; $div_total= $stock*100*0.0678; $stock_total = $stock + int($a/100); push (@stocknum, $stock_total); push (@dividend, $div_total); if ($#dividend == 20) { last; } } dividend (@dividend); sub dividend { @new = shift; $stock_num = $stocknum[-1]; $div = $stock_num*100*0.0678; push (@_, $div); @hash{@stocknum} = @_; foreach $key(sort keys %hash) { print "Stock number: $key\t"."Dividend: $hash{$key}\n"; } } $dividend=0.0378;
Thanks for the help in advance!

In reply to dividend with recursive routine by derpp

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.