in reply to Weird behaviour with match-time code evaluation and backtracking
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Weird behaviour with match-time code evaluation and backtracking
by ikegami (Patriarch) on Mar 05, 2008 at 09:42 UTC |