in reply to calling a function based on a condition

unless is a statement modifier that executes the statement if that statement is false. You are essentially going into reverse; however, unless not reverses the reverse, basically saying that it's true. That's not what you want. The correct expression to use would be unless exists. For example:
#!/usr/bin/perl use strict; use warnings; my %options; call_view() unless exists $options{'r'}; sub call_view { print "doesn't exist.\n"; }
call_view() is called because $options{'r'} doesn't exist.

Replies are listed 'Best First'.
Re^2: calling a function based on a condition
by wfsp (Abbot) on Mar 14, 2011 at 08:46 UTC
    reverses the reverse
    reminds me of a UK West Country phrase
    theze bin an gotten whur thee casn't back'n assn't
    You would think that it wouldn't be possible but every driver knows that it is.

    I have the same trouble with unless. It is very simple but I too often get it wrong. I tend to stick with

    ... if not exists $options{'r'};
    Not as elegant but it tends to increase my chances :-)