hoafaloaf has asked for the wisdom of the Perl Monks concerning the following question:

I'm working in a tcsh environment, and the builtin "killall" just isn't doing it for me.

So ... I decided to try and write an alias (using in-line perl) that would do what I want:
alias ka 'ps -ef|&perl -n -e '"'"'END{@a&&kill(9,@a)}($a=(split())[1]) +!=$$&&/\!:1/&&kill(2,$a)&&push(@a,$a)&&print'"'"''
The problem is, if I use this alias without specifying any arguments I get a "bad ! arg selector" message (because of the "!:1" reference). Is there any way to trap the error message output in the code -- or make sure that the code never gets to the point where it needs to worry about it?

Also, it'd be great if I could get away from using my @a and $a temporary variables, but that's beyond the real scope of my question. :^)

Thanks a bunch!

Replies are listed 'Best First'.
Re: tcsh/perl alias question ...
by Anonymous Monk on Apr 01, 2009 at 09:37 UTC
    Something like alias ka ~/mykaproper.pl
      But that's cheating!

      I think environmental variables are the way to go, actually (just figured this out):
      alias ka 'setenv _KA_ '"'"'\!*'"'"';ps -ef|&perl -n -e '"'"'BEGIN{$A=( +split(" ",$ENV{"_KA_"}||exit(0)))[0]}END{@a&&kill(9,@a)&&print"Killed +: @a\n":"No process found to kill!\n"}($a=(split())[1])!=$$&&/$A/&&ki +ll(2,$a)&&push(@a,$a)&&print'"'"''
      How's that?