in reply to exists function used with attributes/operators?

Yes, you are right, that's Perl's "ternary operator."

Fewer keystrokes and often more readable than an if ... then ... else block.

One of the most useful features is that you can nest them! Here's an exaggerated example (I would use a lookup hash if there were so many choices), with the logic reversed from your OP so we can test a little more deeply:

my $C = ! exists $opts{'c'} ? 'missing' : $opts{'c'} eq '' ? '' : $opt +s{'c'} > 100 ? 'a lot' : $opts{'c'} > 10 ? 'some' : $opts{'c'} > 1 ? +'a few' : $opts{'c'} < 1 ? 'none' : 'one';

Usually I enclose the condition to be evaluated in parentheses (you will have to if you are testing for more than one condition), and write the statement on multiple lines for clarity:

my $C = (! exists $opts{'c'}) ? 'missing' : ($opts{'c'} eq '') ? '' : ($opts{'c'} > 100) ? 'a lot' : ($opts{'c'} > 10) ? 'some' : ($opts{'c'} > 1) ? 'a few' : ($opts{'c'} < 1) ? 'none' : 'one';

HTH

Update: added error handling to code.

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: exists function used with attributes/operators?
by bArriaM (Novice) on Jul 19, 2015 at 15:32 UTC

    Thank you!!