I have a negatable option defined as top!.
When a command uses this option, say : command_name -top, prints a warning to the user
Code snippet for it is as follows :
if ($args{top}) { print "Warning"; }
But, when a command uses a negated option, say : command_name -notop, it does not print the same warning to the user.
Is there a way to get same warning for both the cases?
Yes, you can determine if your option (in either form) has been used on the command line or not. Since you are using a hash for your options, you can check if the option exists:
This will print
Warningif you use either-topor-notopon the command line. It will not printWarningif you do not use-topor-notop.