You may find this an interesting starting point:

use strict; use warnings; my $x = "3 _ 4"; #in polar form.. 3 is mag and 4 is angle my $y = "1i2"; #in rectangular form print join ", ", constructComplex ($x); print "\n" . join ", ", constructComplex ($y); sub constructComplex { my $value1 = shift; my @construct; my ($a, $Form, $b) = $value1 =~ /([-+e.\d]+)\s*([i_])\s*([-+e.\d]+)/; return undef if ! defined $b; $value1 = $_[0]; if ($Form eq '_') { #uses $value1 to pick out the magnitude and angle my ($magnitude, $angle) = ($a, $b); $construct[2] = $magnitude; $construct[3] = $angle; # Do da polar to rect conversion } else { my ($real, $complex) = ($a, $b); $construct[0] = $real; $construct[1] = $complex; # Do da rect to polar conversion } return @construct; }

Ignoring undef related warnings it prints:

, , 3, 4 1, 2

Perl is Huffman encoded by design.

In reply to Re: Constructing complex numbers using recursion by GrandFather
in thread Constructing complex numbers using recursion by moltar512

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.