From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Perl Perl Sent: 08 June 2009 14:23 To: perl-win32-users@listserv.activestate.com Subject: Compilation (Building ) of project once the file is saved + Perl/Tk
> Hi All, > > I am doing this activity on Perl/TK. > > I have to build my project, once the project(file) is created. Problem I am facing here is, the size of > the created project file is showing as 0, and content is nill, which avoiding me to to build the project. > If I close the wideget then I can see the file with file size and data content. > > Let me update you all, I have different buttons like Create, Update and Build. > Build button calles the above functions, which "saves" and "build" the project. > > sub Compile_M3 { > > $Filename = $filename . "\_" . "CPU" . "\." . "pjt"; Why escape _ and .? Your code could be simpler. my $Filename = $filename . "_CPU.pjt"; or my $Filename = "${filename}_CPU.pjt"; > chomp($Filename); Why? If $filename has a record separator at the end, then you are too late. Also, try to avoid confusingly similar variable names, like $Filename and $filename, that only differ in the case of one letter. Its far to easy to use the wrong one. If the variables are also global, this can lead to hard to find bugs. > > $info = "Saving '$Filename'"; > open (FH, ">$Filename"); > print FH $x->get("1.0", "end"); > $info = "Saved."; So when do you close the file? If you use a localised file handle you do not actually need to close the file explicitly. For example (and notice the check for success, which should always be done) open my $fh, ">", $Filename or die "Failed to open $Filename: $!\n"; print $fh $x->get("1.0", "end"); But it is better to explicitly close the file, and, especially as it is an output file, to test if it was successful: close $fh or die "Failed to close $Filename: $!\n"; > > ## Script to build by project ( Here I am giving some dummy command to avoid any conflict with the organization > norms. > #system("/View/Vobs>tools/Perl/bin/perl tools/Compile tools/Perl/bin/perl tools/pjtCompile.pm /View/Vobs/ > $Filename"); > } Also, it looks like you are (a) using global variables, or (b) not including 'use strict;' at the start of your code. Try to avoid (a), and always do (b). HTH -- Brian Raven This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs