#!/usr/bin/perl use warnings; use strict; use Getopt::Long; my ( $execute, $key); GetOptions ( "key=s" => \$key, "execute" => \$execute)||die; my %cmds = ( a => sub {exec 'perl -e "print map {qq!\t$_\n!}"',@_ }, b => sub {exec 'perl -e "$|++;print qq(ee r r );sleep 5"'}, c => sub {my $res; foreach (@ARGV) {$res+=$_}; print $res;exit 0 }, ); if ($execute && exists $cmds{$key} ) { print "ole\n"; $cmds{$key}->(@ARGV); } # theoretically never here .. print "still in \@ARGV: ", (join("|",@ARGV),"\n"); #### echo 1 2 3 | code-dispatch.pl --execute --key c #### echo 1 2 3 | code-dispatch.pl --execute --key a