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

Hi, I am trying to use this one liner in a perl script with back tags (`)
$echo=`alarm() { /bin/perl -e "alarm shift; exec @ARGV " '$@'; } ;ala +rm 4 " while [ 1 ]; do echo ' ' ;done "`; print "$echo";
But it doesnt seem to be working. Can you help me run that line from a script instead of a command line. Thank you

Replies are listed 'Best First'.
Re: one liner in script
by choroba (Cardinal) on Apr 12, 2010 at 14:08 UTC
    Can you please specify what the script should do, according to your intentions?
      Actually I have a much larger perl script where I run a bunch of commands from the command line in between back tacs like
      $line=`cmd 1; cmd 2 ; cmd 3 .... cmd n `;
      Now for one of the commands I have to run it for only 4 secs. Now the only way I could come up with is like this : alarm() { /bin/perl -e 'alarm shift; exec @ARGV' "$@"; } ;alarm 4 'cmd 4 ' Now when I try to put that in a perl script between back tacs it doesnt work. This code doesnt work.
      $line=`cmd 1; cmd 2 ; cmd 3 ;alarm() { /bin/perl -e 'alarm shift; exec + @ARGV' "$@"; } ;alarm 4 'cmd 4 '.... cmd n `;
      Is there anyway I can make the cmd 4 run for 4 secs only.
        This code works for me:
        $line=` cmd 1 cmd 2 cmd 3 alarm () { /usr/bin/perl -e ' alarm shift; exec \@ARGV;' -- "\$@" } alarm 4 cmd 4 cmd n `; print "$line";
        The differences are:
        1. path to perl (might be different on your system)
        2. escaping the @ sign
        3. escaping the $ sign
        4. Update: the -- separator