Use our instead of my and your code will work as you expect.
C:\test\DBMNested>p1 [0] Perl> sub getChecksum($) { my $in = shift; our $check = 0; $in =~ m/(?:(.)(?{$check += ord($1);}))*^/; return $check; };; print getChecksum( 'foo' );; 324 print getChecksum( 'foo' );; 324 print getChecksum( 'foobar' );; 633
Though its a very slow way to achieve your goal. Corion's unpack tip is the way to go.
In reply to Re: Weird behaviour with match-time code evaluation and backtracking
by BrowserUk
in thread Weird behaviour with match-time code evaluation and backtracking
by moensch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |