gg48gg has asked for the wisdom of the Perl Monks concerning the following question:
In reference to Die silently?, an awesome thread, especially the 'fart' code and the explanations of it...
I recently ran into the need to "die silently", while using the below code. I was getting unwanted "\n"'s inserted that I could not explain. I ended up removing the "die" statement and it works as I want, but I am not sure if I am doing something incorrect (not killing my system command?). This is really my first attempt in using a timed out system command via eval/alarm and could use some review and constructive feedback. Here is my code if you care to help...
sub get_size { my $disk=$_[0]; my $size; eval { local $SIG{ALRM} = sub { print_debug("get_size timed out for device $disk"); die; }; alarm(4); $size=qx(bootinfo -s $disk 2>/dev/null); alarm(0); }; $size=($size)? $size : "unknown"; chomp $size; return $size; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: die silently in an eval block while using alarm
by andal (Hermit) on Feb 22, 2013 at 07:49 UTC | |
by gg48gg (Sexton) on Feb 22, 2013 at 21:55 UTC | |
by andal (Hermit) on Feb 25, 2013 at 09:56 UTC | |
|
Re: die silently in an eval block while using alarm
by 7stud (Deacon) on Feb 22, 2013 at 07:28 UTC |