in reply to Re: Validating a Regexp
in thread Validating a Regexp

sub is_valid_re { eval { qr/$_[0]/ }; return $@ ? 'NO' : 'YES'; }

This eval returns a regex or undef, so you could write as follows:

sub is_valid_re { eval { qr/$_[0] } ? 'YES' : 'NO' }
But I'd _never_ return words when a boolean value is needed. Digits are so much nicer for that. If you want words, you could create yet another sub to turn the truth number into a word.
sub is_valid_re { eval { qr/$_[0] } } print is_valid_re('abc') ? 'YES' : 'NO'; sub human_bool { shift ? 'YES' : 'NO' } print human_bool(is_valid_re('abc'));

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.