August 2015 Archives

Dispatch Tables


use strict;
use warnings;

sub greet { print "Hello!\n" }
sub inquire { print "How are you?\n" }
sub bye { print "Farewell!\n" }
sub delete_all_files { print "*KABOOM*\n" }

sub insecure_call {
no strict 'refs';
shift->();
}

insecure_call('greet');
insecure_ca…

Accepting Input from Multiple Sources

One of the corners I often paint myself into when developing a tool is only accepting one type of input, usually STDIN, the standard input stream, like a pipeline (ex: cat fruit.txt | grep apple) or a redirect (ex: grep apple < fruit.txt)

What inevitably happens is I end up wanting the tool to work like any Unix tool and accept different kinds of input (filenames or arguments on the command line, for example.)

Finally I got fed up with it and added a function called multi_input()/users/tinypig/2015/08/index.html

About tinypig

user-pic I blog about Perl.