在C程序上运行perl脚本时,我得到GLOB(0x1a6a8830)作为输出

时间:2011-03-11 09:35:31

标签: c perl scripting glob

对于我的一个项目,我们必须在C中编写一个多线程程序。一切似乎进展顺利。然后教授给我们一个perl脚本,一旦完成我们的C代码。但是,在我运行脚本的控制台上,无论何时我的程序应该输出(我认为),我都会获得GLOB(0x1a6a8830)。这是输出。

GLOB(0x1a6a8830)

TRANS 995 -589398 987 154107 472 435291

GLOB(0x1a6a8830)

TRANS 397 -557927 559 798860 989 -240933

GLOB(0x1a6a8830)

TRANS 289 -368267 408 139828 419 842413 277 -598329 613 372608 285 508034 256 -896287

使用TRANS(然后是数字)作为我的C程序捕获的输入。有谁知道这个GLOB是什么????

use strict;
use warnings;
use integer;

if (@ARGV < 1) {

print "Use: $0 <program> [<nthreads> [<naccounts> [<seed>]]]\n";
exit 1;
}

my($prgm, $thread, $accts, $seed) = @ARGV;

$thread ||= 10;
$accts ||= 1000;
$seed ||= 0;

srand($seed);

my $outfile = 'testout-'.$$;
my($c_in, $f_in, $c_out, $f_out);
pipe $f_in, $c_in;
pipe $c_out, $f_out;
my $pid = fork;

`if ($pid == 0) {
open STDIN, '<&', $f_in;
open STDOUT, '>&', $f_out;
close $c_in;
close $c_out;
close $f_in;
close $f_out;
exec $prgm, $thread, $accts, $outfile;
exit 1;
} else {
close $f_in;
close $f_out;
}

# make the pipes autoflush
select $c_in; $| = 1;
select $c_out; $| = 1;
 select STDOUT;

sub sr {
my $line = shift;
print "\e[33m$line\e[m\n";
print $c_in "$line\n";
my $resp = $c_out;
chomp $resp;
print "\e[32m$resp\e[m\n";
return $resp;
}

my $init_skip = 0;
for my $id (0..($accts/10 - 1)) {
my $line = 'TRANS';
$line .= ' '.($id*10 + $_).' 10000000' for 1..10;
sr $line;
$init_skip++;
}

    print "\e[35mWaiting for initial deposits to complete...\e[m\n";
   sleep 60;

for my $line (1..1000) {
my $line = "TRANS";
my $bal = 0;
my $len = int rand 8;
my %dups;
for (0..$len) {
    my $acct = 1 + int rand $accts;
    my $amt = 1_000_000 - int rand 2_000_000;
    next if $dups{$acct}++;
    $bal += -$amt;
    $line .= " $acct $amt";
}
my $acct = 1 + int rand $accts;
next if $dups{$acct};
$line .= " $acct $bal";
sr $line;
}

print "\e[35mWaiting for transactions to complete...\e[m\n";
sleep 60;

for my $id (1..$accts) {
sr "CHECK $id";
}

print "\e[33mEND\e[m\n";
print $c_in "END\n";
print "\e[35mWaiting for program to exit...\e[m\n";
wait;
no integer;
print "\e[35mChecking output file:\e[m\n";

open F, $outfile;
my $trcount = 0;
my $trtime = 0;
my $balcount = 0;
my $baltime = 0;
my $total = 0;
while (<F>) {
if ($init_skip-- > 0) {
    die "Bad (initial deposit) output line: $_" unless /^\d+ OK TIME/;
} elsif (/ (OK|ISF \d+) TIME (\d+)(\.\d+) (\d+)(\.\d+)/) {
    $trtime += ($4 - $2) + ($5 - $3);
    $trcount++;
} elsif (/^\d+ BAL (\d+) TIME (\d+)(\.\d+) (\d+)(\.\d+)/) {
    $total += $1;
    $baltime += ($4 - $2) + ($5 - $3);
    $balcount++;
} else {
    die "Bad output line: $_";
}
}
close F;

if ($balcount != $accts) {
print "ERR: There were $accts accounts but only $balcount balance queries\n";
}
print "Final balance of all $accts accounts is $total\n";
my $travg = $trtime / $trcount;
printf 'The %d transactions took %.2fs total, or an average of %.4fs each'."\n",
$trcount, $trtime, $travg;
my $balavg = $baltime / $balcount;
printf 'The %d balance checks took %.2fs total, or an average of %.4fs each'."\n",
$balcount, $baltime, $balavg;

这是整个perl脚本

我的程序充当多线程银行服务器,并接受命令TRANS和CHECK

2 个答案:

答案 0 :(得分:4)

乍一看,我发现脚本中有两个拼写错误。首先是第25行的`。第二行是

my $resp = $c_out;

即将文件句柄分配给$resp而不是从中读取。应该是这样的:

my $resp = <$c_out>;

答案 1 :(得分:1)

它是对glob的引用。有人可能会留下调试打印件。在perl脚本中搜索可疑的print命令并将其注释掉。