diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-07-03 16:51:29 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-07-03 16:51:29 +0100 |
| commit | 68d9cb2252c468c8cf8a76c0468819025c170230 (patch) | |
| tree | bc3c8da8a5822c1939751a0fe0c5cefafdd5165c | |
| parent | 84571d179d4c1fbc6ef1a21a817bc639c4c49880 (diff) | |
| download | perlweeklychallenge-club-68d9cb2252c468c8cf8a76c0468819025c170230.tar.gz perlweeklychallenge-club-68d9cb2252c468c8cf8a76c0468819025c170230.tar.bz2 perlweeklychallenge-club-68d9cb2252c468c8cf8a76c0468819025c170230.zip | |
defensive coding
| -rw-r--r-- | challenge-119/james-smith/cesil/cesil.pl | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/challenge-119/james-smith/cesil/cesil.pl b/challenge-119/james-smith/cesil/cesil.pl index 8a969cd4f4..61c724ca9c 100644 --- a/challenge-119/james-smith/cesil/cesil.pl +++ b/challenge-119/james-smith/cesil/cesil.pl @@ -1,4 +1,5 @@ use strict; +use warnings; $| = 1; my( $ptr, @in, %mem, @code, %ptrs, $reg ) = 0; @@ -21,10 +22,13 @@ my %commands = ( ); while(<>) { - (@in = map { 0+$_ } <> ) && last if m{^ {8}%}; + ((@in = map { 0+$_ } <> ),last) if m{^ {8}%}; ($ptrs{$1},$_)=(scalar @code,$2) if m{^(\S{1,7})\s+(.*)}; push @code, [ split m{\s+}, s{^\s+}{}r=~s{\s+$}{}r, 2 ]; } -($commands{$code[$ptr][0]}($code[$ptr][1]),$ptr++) for 1..1e6; + +my $MAX_LOOPS = 1e6; +($commands{$code[$ptr][0]}($code[$ptr][1]),$ptr++) + while --$MAX_LOOPS && $ptr<@code; |
