in reply to Inexplicable uninitialized value when using (?{...}) regexp construct.
Switching my for our works fine for me with identical setup: AS 5.8.4/XP. Though I have AS 510 and there was an earlier version (AS508?) which I saw another problem that the move to 510 fixed. Maybe this is another?
use strict; use warnings; while ( <DATA> ) { chomp; print bin_to_dec($_), "\n"; } sub bin_to_dec { my $bits = shift; our( $power, $magnitude, $num ); die "$bits is not a pure bit string.\n" if $bits =~ m/[^10]/; if ( $bits =~ m/ (?{ $power = length($_) - 1; $num = 0; }) (?: ([10]) (?{ $magnitude = 2 ** $power; $^N eq '1' and $num += $magnitude; $power--; }) )+ /x ) { return $num; } else { die "Unable to resolve bits: $bits.\n"; } } __DATA__ 00000000 00000011 00000111 11100000 __OUTPUT__ P:\test>junk 0 3 7 224
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inexplicable uninitialized value when using (?{...}) regexp construct.
by davido (Cardinal) on Sep 28, 2004 at 20:41 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2004 at 00:24 UTC | |
by davido (Cardinal) on Sep 29, 2004 at 01:15 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2004 at 01:36 UTC | |
by diotalevi (Canon) on Sep 28, 2004 at 22:55 UTC |