in reply to C and other stuff

Your assert function won't be able to see lexical variables.

my $x = 42; assert '$x > 40'; # assertion fails, # because eval can't see $x

Better is to write assert so that it takes a code ref...

sub assert (&) { require Carp; (shift)->() ? 1 : Carp::croak('Assertion failed') } my $x = 42; assert { $x > 40 }; # assertion ok

Also, I'd recommend giving your pseudo-constants TRUE, FALSE and EXIT_SUCCESS an empty prototype - i.e. () - and not using the return keyword in them. This allows the Perl compiler to treat them as real constants - inlining them into code that calls them. And if will solve your problems that lead them to occasionally needing to be called with a leading &.

sub TRUE () { 1 } sub FALSE () { 0 } sub EXIT_SUCCESS () { TRUE }
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: C and other stuff
by perlaintdead (Scribe) on Jan 12, 2014 at 19:10 UTC
    thanks