希望大家帮小弟我看下这段perl代码
希望大家帮我看下这段perl代码
# This program is to convert CSV format to SVMlight format data set
#!perl -w inputCSV outputSVML
use strict;
die "Usage: command in_set outputfile\n" if scalar(@ARGV) < 2;
my ($inputfile, $out_file ) = @ARGV;
my $line_num = 0;
my $counterp = 0;
my $countern = 0;
my $counter = 0;
open(IN, $inputfile) || die(" Can not open file(\"$inputfile\").\n");
open(OUT, "> $out_file") || die(" Can not open file(\"$out_file\").\n");
$line_num = 0;
while (<IN>)
{
chomp;
my $per_line = $_;
my @items = split(',', $per_line);
my $flag = $items[$#items];
if ($flag != 1) {
print OUT "-1";
$countern = $countern + 1;
}
else {
print OUT "1";
$counterp = $counterp + 1;
}
for($counter = 0 ; $counter < $#items ; $counter++)
{
my $temp = $counter + 1;
print OUT " $temp:$items[$counter]";
}
print OUT "\n";
$line_num = $line_num +1;
}
print "\n $line_num lines; pos: $counterp + rand: $countern \n\n";
close(IN);
close(OUT);
在matlab中执行:
cv_cmd = sprintf('!perl ../trainTest/convert_file_forSvm.pl %s %s > %s', testCSVfile, temp_test_file, garbage_file);
eval(cv_cmd);
出错,希望大家看看帮我解决一下!
谢谢!
------解决方案--------------------
你在什么系统平台下?
如果是linux,应该是问题的,因为它缺省安装有perl,且已设好路径
如果是windows,首先你要确认你系统安装了perl,如果安装了perl,要将perl的执行路径加入你的PATH
或在程序中加入它的全路径:
cv_cmd = sprintf('!c:\\perl\\bin\\perl ...
------解决方案--------------------
可以输出 cv_cmd 的内容来看看对不对
# This program is to convert CSV format to SVMlight format data set
#!perl -w inputCSV outputSVML
use strict;
die "Usage: command in_set outputfile\n" if scalar(@ARGV) < 2;
my ($inputfile, $out_file ) = @ARGV;
my $line_num = 0;
my $counterp = 0;
my $countern = 0;
my $counter = 0;
open(IN, $inputfile) || die(" Can not open file(\"$inputfile\").\n");
open(OUT, "> $out_file") || die(" Can not open file(\"$out_file\").\n");
$line_num = 0;
while (<IN>)
{
chomp;
my $per_line = $_;
my @items = split(',', $per_line);
my $flag = $items[$#items];
if ($flag != 1) {
print OUT "-1";
$countern = $countern + 1;
}
else {
print OUT "1";
$counterp = $counterp + 1;
}
for($counter = 0 ; $counter < $#items ; $counter++)
{
my $temp = $counter + 1;
print OUT " $temp:$items[$counter]";
}
print OUT "\n";
$line_num = $line_num +1;
}
print "\n $line_num lines; pos: $counterp + rand: $countern \n\n";
close(IN);
close(OUT);
在matlab中执行:
cv_cmd = sprintf('!perl ../trainTest/convert_file_forSvm.pl %s %s > %s', testCSVfile, temp_test_file, garbage_file);
eval(cv_cmd);
出错,希望大家看看帮我解决一下!
谢谢!
------解决方案--------------------
你在什么系统平台下?
如果是linux,应该是问题的,因为它缺省安装有perl,且已设好路径
如果是windows,首先你要确认你系统安装了perl,如果安装了perl,要将perl的执行路径加入你的PATH
或在程序中加入它的全路径:
cv_cmd = sprintf('!c:\\perl\\bin\\perl ...
------解决方案--------------------
可以输出 cv_cmd 的内容来看看对不对