Lol, you've got to love a refresher in middle-school math. ;) Thanks.

Taking that into consideration, and adding a built-in string validity check, here's how the working code now looks:

use strict; use warnings; use Carp; while ( <DATA> ) { chomp; print "$_\t=>\t", bin_to_dec($_), "\n"; } sub bin_to_dec { our $num; # $num must be a global to work. local $num; # Play nice if $num is already in global use. $_[0] =~ m/ (?=^[10]+$) # Check for a valid string. (?{ $num = 0; }) (?: ([10]) (?{ $num = 2 * $num + $^N; }) )+ /x or croak "Error: $_[0] is not a pure bit string.\n"; return $num; } __DATA__ 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Thanks again...


Dave


In reply to Re^2: Inexplicable uninitialized value when using (?{...}) regexp construct. by davido
in thread Inexplicable uninitialized value when using (?{...}) regexp construct. by davido

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.