mardi 14 juin 2016

Print to file using Perl Tk

I've solved most of the issues with my code, but now everything in my list box gets printed to a file regardless of whether it is checked or not. Not sure why. Any help is appreciated. I had this working before, but not sure what I did to change it. I'd like for when an item is checked and you click OK, then Exit, that only the items that are checked get copied over to the file.

use strict;
use warnings;
use Tk;
open(INFILE,"d1528235.txt") or die "could not open file for reading!n";
open(OUTFILE, '>forecast.txt') or die "Cannot open forecast.txt: $!";


while(<INFILE>){
  if (m/^s*$/) { next; }
  chomp $_;
  my @fields = split(/  /,$_);
  my @output;
  foreach my $field(@fields){
    if($field =~ /^*?[ABMQRWY][A-Z0-9]{4}235 / ){
      push @output,$field;

  }


     }

  if (@output) {
    my $line = join('',@output);
    print "$linen";
    print OUTFILE "$linen";
  }
}

my $mw = MainWindow->new;
$mw->geometry("300x500");
$mw->title("Unforecasted Jobs");

my $check1 = 'NOT CHECKED';
my $check2 = 'NOT CHECKED';
my $check3 = 'NOT CHECKED';
my $check4 = 'NOT CHECKED';
my $check5 = 'NOT CHECKED';
my $check6 = 'NOT CHECKED';
my $check7 = 'NOT CHECKED';
my $check8 = 'NOT CHECKED';
my $check9 = 'NOT CHECKED';
my $check10 = 'NOT CHECKED';
my $check11 = 'NOT CHECKED';
my $check12 = 'NOT CHECKED';
my $check13 = 'NOT CHECKED';
my $check14 = 'NOT CHECKED';
my $check15 = 'NOT CHECKED';
my $check16 = 'NOT CHECKED';

my $check_frame = $mw->Frame()->pack(-side => "top");
$check_frame->Label(-text=>"Jobs That Do Not Forecast")->pack(-side =>  "top")->pack();
my $job = "18L";
my $chk1 = $check_frame->Checkbutton(-text => '18-Letters',
                                 -variable => $check1,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$jobn";

my $job2 = "07O";
my $chk2 = $check_frame->Checkbutton(-text => '07-Orders',
                                 -variable => $check2,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job2n";

my $job3 = "36L";
my $chk3 = $check_frame->Checkbutton(-text => '36-Letters',
                                 -variable => $check3,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack();
                                 -command => print OUTFILE "$job3n";

my $job4 = "38L";
my $chk4 = $check_frame->Checkbutton(-text => '38-Letters',
                                 -variable => $check4,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job4n";

my $job5 = "11O";
my $chk5 = $check_frame->Checkbutton(-text => '11-Orders',
                                 -variable => $check5,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job5n";

my $job6 = "99L";
my $chk6 = $check_frame->Checkbutton(-text => '99-Letters',
                                 -variable => $check6,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack();
                                 -command => print OUTFILE "$job6n";

my $job7 = "21L";
my $chk7 = $check_frame->Checkbutton(-text => '21-Letters',
                                 -variable => $check7,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job7n";

my $job8 = "23L";
my $chk8 = $check_frame->Checkbutton(-text => '23-Letters',
                                 -variable => $check8,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job8n";

my $job9 = "OOO";
my $chk9 = $check_frame->Checkbutton(-text => 'Return to LNI',
                                 -variable => $check9,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack();
                                 -command => print OUTFILE "$job9n";

my $job10 = "EOSSS235";
my $chk10 = $check_frame->Checkbutton(-text => 'EOSSS235',
                                 -variable => $check10,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job10n";

my $job11 = "M4020235 20";
my $chk11 = $check_frame->Checkbutton(-text => 'M4020235',
                                 -variable => $check11,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job11n";

my $job12 = "PRTAR235";
my $chk12 = $check_frame->Checkbutton(-text => 'PRTAR235',
                                 -variable => $check12,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack();
                                 -command => print OUTFILE "$job12n";

my $job13 = "WR115235";
my $job13b = "WR415235";
my $chk13 = $check_frame->Checkbutton(-text => 'WR115235',
                                 -variable => $check13,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job13n$job13bn";

my $job14 = "X01RA235";
my $chk14 = $check_frame->Checkbutton(-text => 'X01RA235',
                                 -variable => $check14,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack(),
                                 -command => print OUTFILE "$job14n";

my $job15 = "X1514235 15";
my $chk15 = $check_frame->Checkbutton(-text => 'X1514235',
                                 -variable => $check15,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack();
                                 -command => print OUTFILE "$job15n";

my $job16 = "X4020235";
my $chk16 = $check_frame->Checkbutton(-text => 'X4020235',
                                 -variable => $check16,
                                 -onvalue => 'ADDED',
                                 -offvalue => 'NOT CHECKED')->pack();
                                 -command => print OUTFILE "$job16n";


my $button_frame = $mw->Frame()->pack(-side => "bottom");
my $ok_button = $button_frame->Button(-text => 'OK',
                                   -command => &check_sub)->pack(-side => "left");
my $exit_button = $button_frame->Button(-text => 'Exit',
                                    -command => sub{$mw->destroy})->pack(-side => "right");

sub check_sub {
  my $check_msg = "18-Letters: $check1n07-Orders: $check2n36-Letters: $check3n38-Letters: $check4n11-Orders: $check5n99-Letters: $check6n21-Letters: $check7n23-Letters: $check8nReturn L&I: $check9nEOSSS235: $check10nM4020235: $check11nPRTAR235: $check12nWR115235: $check13nWR415235: $check13nX01RA235: $check14nX1514235: $check15nX4020235: $check16";
  $mw->messageBox(-message => "Check Button Summary:n$check_msg", -type => "ok");
}

MainLoop;

my $var =`crossref.pl`;

Aucun commentaire:

Enregistrer un commentaire