I'm building a script that uses a sub-routine for user-interaction:

if ( &ask('Do you want to do this?') ) {
        # do stuff
}

I'd like to have a switch variable that allows me to toggle the 
user-interaction mode. In other words, if $interact is false then ask() will 
not prompt the user and will return true.

I see that Perl does not complain if I do this ...

my $interact = 0;

sub ask {
        return 1 unless $interact;
        # otherwise do user-prompt stuff
}

... but is that considered bad programming practice? It seems like unnecessary 
extra typing to pass $interact as an argument to the sub-routine every time, or 
to always do "if ( (! $interact) || &ask )".

Many TIA,
James Harvard

Reply via email to