http://www.perlmonks.org?node_id=654625


in reply to Is it possible to determine last executed command line?

This may be a bit overkill, and definitely defines additional variables, but you could use a hash to store the command and any errors.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Digest::MD5; use IPC::Run qw( run timeout ) ; my %syscalls; runsyscall('/usr/bin/ls'); runsyscall('/bin/ls'); runsyscall('vipw'); print Dumper %syscalls; sub runsyscall { my @cmd = @_; my $digest = digestit(@cmd); my ( $in, $out, $err ); $syscalls{$digest}{'cmd'} = qq|@cmd|; eval { run \@cmd, \$in, \$out, \$err, timeout 10 }; if ($@) { $syscalls{$digest}{'exit'} = $@; } chomp ($err) if $err; # chomp ($out) if $out; $syscalls{$digest}{'err'} = $err || undef; # $syscalls{$digest}{'out'} = $out || undef; } sub digestit { my @cmd = @_; my $sysdigest = Digest::MD5->new; $sysdigest->add(@cmd); return $sysdigest->hexdigest; }


Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson