Solved

syntax error in perl

Posted on 2004-10-27
294 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
Question by:TPoly
    3 Comments
     
    LVL 48

    Expert Comment

    by:Tintin
    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
    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 84

    Accepted Solution

    by:
           $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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    Suggested Solutions

    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    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…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now