in reply to Doing "it" only once
You could do something with overload instead of subrefs. I'm not sure how much faster this will be, but here goes:
package Always::False; use overload 'bool' => sub { return; }; sub new { return bless \(my $foo), shift } package Check::Once; use overload 'bool' => 'boolify'; sub new { my $class = shift; my ($val) = @_; return bless \$val, $class; } sub boolify { if (${$_[0]} eq $_) { $_[0] = Always::False->new; return 1; } else { return; } } package main; my $once_only = Check::Once->new('foo'); while (<FILE>) { next if $once_only; # Other stuff here. }
Yes, there are improvements that could be made, but it's just proof-of-concept.
|
|---|