Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

syntax error in perl

Posted on 2004-10-27
3
Medium Priority
?
307 Views
Last Modified: 2010-03-05
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);
0
Comment
Question by:TPoly
3 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 12429955
There's not enough info to go on.

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.
0
 

Author Comment

by:TPoly
ID: 12430121
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(-yscrollcommand=>['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:rvsi','','', {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);
}
}




0
 
LVL 85

Accepted Solution

by:
ozo earned 450 total points
ID: 12430284
       $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" );
        }
This  ^   right bracket has no corresponding left bracket.
The beginning of the file seems to be missing something.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question