in reply to Re: how to check syntax of code inside a scalar?
in thread how to check syntax of code inside a scalar?
Uggh, it's a bit shortsighted that there's no built-in function for this. However, after playing a bit, I've found that this can be simulated without having to actually execute the scalar's contents by pre-pending "return;" and testing with eval:
sub syntax_ok { my $source = "return;\n" . shift; eval $source; return 1 unless $@; return 0; }
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to check syntax of code inside a scalar?
by Crackers2 (Parson) on Aug 04, 2010 at 21:04 UTC | |
by snoopy (Curate) on Aug 04, 2010 at 21:55 UTC | |
by aquarium (Curate) on Aug 05, 2010 at 03:39 UTC | |
by snoopy (Curate) on Aug 05, 2010 at 05:05 UTC |