in reply to match function
use strict; use warnings; print "Enter a string: "; chomp ($_ = <>); my $msg = !/a/i ? 'String did not match' : !/a.*b/i ? 'The string has an a, but not a following b' : 'The string has an a, but also a following b' ; print $msg, "\n";
UPDATE: Even better, use positive tests:
my $msg = /a.*b/i ? 'The string has an a, and also a following b' : /a[^bB]*$/i ? 'The string has an a, but not a following b' : 'String did not match' ;
|
|---|