<?xml version="1.0" encoding="windows-1252"?>
<node id="1007553" title="Need Help With Alarm And Eval" created="2012-12-06 07:04:33" updated="2012-12-06 07:04:33">
<type id="115">
perlquestion</type>
<author id="1007012">
PerlRocks6345</author>
<data>
<field name="doctext">
&lt;p&gt; Hi Monks the code below works perfectly&lt;/p&gt;&lt;code&gt; use strict;
 my $errorName="alarm\n";
 my $time=5;

    eval {
        local $SIG{ALRM} = sub { die "$errorName" };
        alarm $time;
       
        
        sleep(10); 
		
    };
	my $error= $@;
	
	Off($error,$errorName);
	
	sub Off{
	my $error=$_[0];
	my $errorName=$_[1];
  if( $error &amp;&amp; $error eq "$errorName") 
  {
   warn "Timed out!!!\n"; 
   
	exit ;
	}
	else 
	{
	alarm 0;
	print " you can continue";
	}
}
&lt;/code&gt;&lt;p&gt;But when I make it to subroutines as this&lt;/p&gt;&lt;code&gt; use strict;
 my $errorName="alarm\n";
 my $time=5;
    
    eval {
	On($time,$errorName);
        
        #dostuff();
        
        sleep(10); 
    };
	my $error= $@;
	print "error ".$error."error \n";
	Off($error,$errorName);
	
sub On
{
	my $time=$_[0];
	my $errorName=$_[1];
		local $SIG{ALRM} = sub { die "$errorName" };
        alarm $time;
}
	
	
sub Off
{
	my $error=$_[0];
	my $errorName=$_[1];
	if( $error &amp;&amp; $error eq "$errorName") 
		{
			warn "Timed out!!!\n"; 
			
			exit ;
		}
	else 
		{
			alarm 0;
			print " you can continue";
		}
}
&lt;/code&gt;&lt;p&gt; It does not work as expected instead of throwing the warning message it throws "Terminating on signal SIGALRM(14)" Need your help Monks.Thank you in advance &lt;/p&gt;</field>
</data>
</node>
