TPoly
asked on
syntax error in perl
hi..
i have two perl code that create .csv files and the other create .txt file.
How to create both by conbining these 2 sets of codes up?
Keep getting syntax error when i tried tt..
CREATE .csv files
my($csv) = Text::CSV->new;
open( CSV, ">$file.csv") || die "Failed for $file.csv: $!\n";
# Write Header
$csv->combine( qw/Qin Qout Yield Reject/);
print CSV $csv->string . "\n";
# Write data using foreach or some other loop.
$csv->combine( @{$t} );
print CSV $csv->string . "\n";
close( CSV );
__________________________ __________ __________ __________ __________ __________ ______
CREATE text files
die "$file already exists\n" if -f $file;
open FILE, ">$file" or die "Can not create $file $!\n";
#print the sums at the top of the file, separated by tabs
print FILE "Daily Yield Report Summary\n";
print FILE "Device: '$dev'\n";
print FILE "Date: '$datef' to '$datet'\n\n";
print FILE "Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n";
foreach my $r(@$d) {
print FILE join("\t", @$r), $/;}
#write the other arrays in tab-separated columns underneath the sums
print FILE "-"x60, $/;
print FILE "Total\t\t", join("\t", @$t), $/;
# Graph
print FILE $graph->to_string( [("\t", @$t), $/],
labels => [ qw/, ,Qin, Qout, Yield, Reject/ ],
);
close(FILE);
i have two perl code that create .csv files and the other create .txt file.
How to create both by conbining these 2 sets of codes up?
Keep getting syntax error when i tried tt..
CREATE .csv files
my($csv) = Text::CSV->new;
open( CSV, ">$file.csv") || die "Failed for $file.csv: $!\n";
# Write Header
$csv->combine( qw/Qin Qout Yield Reject/);
print CSV $csv->string . "\n";
# Write data using foreach or some other loop.
$csv->combine( @{$t} );
print CSV $csv->string . "\n";
close( CSV );
__________________________
CREATE text files
die "$file already exists\n" if -f $file;
open FILE, ">$file" or die "Can not create $file $!\n";
#print the sums at the top of the file, separated by tabs
print FILE "Daily Yield Report Summary\n";
print FILE "Device: '$dev'\n";
print FILE "Date: '$datef' to '$datet'\n\n";
print FILE "Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n";
foreach my $r(@$d) {
print FILE join("\t", @$r), $/;}
#write the other arrays in tab-separated columns underneath the sums
print FILE "-"x60, $/;
print FILE "Total\t\t", join("\t", @$t), $/;
# Graph
print FILE $graph->to_string( [("\t", @$t), $/],
labels => [ qw/, ,Qin, Qout, Yield, Reject/ ],
);
close(FILE);
ASKER
error msg:
Unmatched right curly bracket at graphtxtcvs.tk line 28, at end of line
(Might be a runaway multi-line "" string starting on line 20)
syntax error at graphtxtcvs.tk line 28, near "}"
Execution of graphtxtcvs.tk aborted due to compilation errors.
the codes:
$ca->createImage(5,2,
-anchor =>'nw',
-image => image1);
$ca->pack(-side=>'top');
$text =
$fr2->ROText('-width'=>85, '-height'= >30,
-font=>['time new roman','10'],-background=> 'white')-> pack(-side =>'bottom' );
my $scr2 = $fr2->Scrollbar(-command =>['yview',$text]);
$text->configure(-yscrollc ommand=>[' set',$scr2 ]);
$text->pack(-side => 'left', -fill =>'both');
$scr2->pack(-side => 'right', -fill => 'y');
$text->insert('1.0',"This program is licensed
to Agilent Technologies Singapore (HSIO)\n
search.tk is created by Dawn Lee and Joyce Khoo,
Diploma in Info-Communications(IFC)\n
This program allows the user to search the directory
for 'Yield Report', 'Tray Report'
and 'Packagae Report'\n
Copyright(c) 2004 Temasek Polytechnic\n" );
}
sub condition1()
{
#Get entry
$devf=$f->get('active');
$dev=$d->get('active');
$datef=$entry2->get;
$datet=$entry3->get;
$file=$entry->get;
$year=$entry4->get;
if ($devf eq "" && $year eq ""){
#connect to the database
my $dbh = DBI->connect('dbi:mysql:rv si','','', {RaiseError=>1, PrintError=>1});
# Extract the data from database
my $d = $dbh->selectall_arrayref(" SELECT date, qin, qout,yield, reject, lot FROM yield WHERE date BETWEEN '$datef' AND '$datet'");
print ("Daily Yield Report Summary for '$dev' between '$datef' to '$datet'\n\n");
print ("Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n");
# Print out all the array catch
foreach my $r(@$d) {
print join("\t", @$r), $/;
}
#print the dotted line
print "-"x60, $/;
#Do the calculation
my $t = $dbh->selectrow_arrayref(" SELECT sum(qin), sum(qout), ((sum(qout)/sum(qin))*100) , sum(reject) FROM yield WHERE date BETWEEN '$datef' AND '$datet'");
print "Total\t\t", join("\t", @$t), $/;
#Create Graph
my $graph = Text::Graph->new( 'Bar' );
print $graph->to_string( [("\t", @$t), $/],
labels => [ qw/, ,Qin, Qout, Yield, Reject/ ],
);
my($csv) = Text::CSV->new;
open( CSV, ">$file.csv") || die "Failed for $file.csv: $!\n";
# Write Header
$csv->combine( qw/Qin Qout Yield Reject/);
print CSV $csv->string . "\n";
# Write data using foreach or some other loop.
$csv->combine( @{$t} );
print CSV $csv->string . "\n";
close( CSV );
die "$file already exists\n" if -f $file;
open FILE, ">$file" or die "Can not create $file $!\n";
#print the sums at the top of the file, separated by tabs
print FILE "Daily Yield Report Summary\n";
print FILE "Device: '$dev'\n";
print FILE "Date: '$datef' to '$datet'\n\n";
print FILE "Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n";
foreach my $r(@$d) {
print FILE join("\t", @$r), $/;}
#write the other arrays in tab-separated columns underneath the sums
print FILE "-"x60, $/;
print FILE "Total\t\t", join("\t", @$t), $/;
# Graph
print FILE $graph->to_string( [("\t", @$t), $/],
labels => [ qw/, ,Qin, Qout, Yield, Reject/ ],
);
close(FILE);
}
}
Unmatched right curly bracket at graphtxtcvs.tk line 28, at end of line
(Might be a runaway multi-line "" string starting on line 20)
syntax error at graphtxtcvs.tk line 28, near "}"
Execution of graphtxtcvs.tk aborted due to compilation errors.
the codes:
$ca->createImage(5,2,
-anchor =>'nw',
-image => image1);
$ca->pack(-side=>'top');
$text =
$fr2->ROText('-width'=>85,
-font=>['time new roman','10'],-background=>
my $scr2 = $fr2->Scrollbar(-command =>['yview',$text]);
$text->configure(-yscrollc
$text->pack(-side => 'left', -fill =>'both');
$scr2->pack(-side => 'right', -fill => 'y');
$text->insert('1.0',"This program is licensed
to Agilent Technologies Singapore (HSIO)\n
search.tk is created by Dawn Lee and Joyce Khoo,
Diploma in Info-Communications(IFC)\n
This program allows the user to search the directory
for 'Yield Report', 'Tray Report'
and 'Packagae Report'\n
Copyright(c) 2004 Temasek Polytechnic\n" );
}
sub condition1()
{
#Get entry
$devf=$f->get('active');
$dev=$d->get('active');
$datef=$entry2->get;
$datet=$entry3->get;
$file=$entry->get;
$year=$entry4->get;
if ($devf eq "" && $year eq ""){
#connect to the database
my $dbh = DBI->connect('dbi:mysql:rv
# Extract the data from database
my $d = $dbh->selectall_arrayref("
print ("Daily Yield Report Summary for '$dev' between '$datef' to '$datet'\n\n");
print ("Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n");
# Print out all the array catch
foreach my $r(@$d) {
print join("\t", @$r), $/;
}
#print the dotted line
print "-"x60, $/;
#Do the calculation
my $t = $dbh->selectrow_arrayref("
print "Total\t\t", join("\t", @$t), $/;
#Create Graph
my $graph = Text::Graph->new( 'Bar' );
print $graph->to_string( [("\t", @$t), $/],
labels => [ qw/, ,Qin, Qout, Yield, Reject/ ],
);
my($csv) = Text::CSV->new;
open( CSV, ">$file.csv") || die "Failed for $file.csv: $!\n";
# Write Header
$csv->combine( qw/Qin Qout Yield Reject/);
print CSV $csv->string . "\n";
# Write data using foreach or some other loop.
$csv->combine( @{$t} );
print CSV $csv->string . "\n";
close( CSV );
die "$file already exists\n" if -f $file;
open FILE, ">$file" or die "Can not create $file $!\n";
#print the sums at the top of the file, separated by tabs
print FILE "Daily Yield Report Summary\n";
print FILE "Device: '$dev'\n";
print FILE "Date: '$datef' to '$datet'\n\n";
print FILE "Date\t\t", "Qin\t", "Qout\t", "Yield\t", "Reject\t", "Lot\n";
foreach my $r(@$d) {
print FILE join("\t", @$r), $/;}
#write the other arrays in tab-separated columns underneath the sums
print FILE "-"x60, $/;
print FILE "Total\t\t", join("\t", @$t), $/;
# Graph
print FILE $graph->to_string( [("\t", @$t), $/],
labels => [ qw/, ,Qin, Qout, Yield, Reject/ ],
);
close(FILE);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can quite easily combine the two code snippets, but without seeing what's wrapped around them and what the syntax error you got, it's not possible to help.