在perl中输入多个文件

时间:2015-02-02 16:49:07

标签: perl perl-data-structures multiple-files

我有一个perl脚本来做这样的事情:

  • 插入10个文件.txt(按钮)
  • 将每个网址打印到文字区域
  • 使用tokenizer处理

这里是剧本:

sub Main_Menu{

 # --------------------
 # Create GUI interface
 # --------------------
 my $mw = MainWindow->new();
    $mw->resizable (0,0); # No resize
    $mw->iconbitmap("$icon");
    $mw->geometry('470x460');
    $mw->title($title);


    # --------------------------------------
    # Create a frame for user authentication
    # --------------------------------------
     my $sub_frm = $mw->LabFrame(-bd => 2, 
                              -label => "Input File",
                         )->place(-x => 10, -y => 10);

    # -------------------------------------------------------
    # Create a Button and Text for inputing File in multiple
    # -------------------------------------------------------
     foreach ("Add File 1","Add File 2","Add File 3","Add File 4","Add File 5","Add File 6","Add File 7","Add File 8","Add File 9","Add File 10"){
        $sub_frm_insert = $sub_frm->Frame(-bd => 2)
                                  ->pack(-side => 'top',
                                         -fill => 'x');
        #------>chap1  
        $input_btn_1 = $sub_frm_insert->Button(-text => "$_",
                                        -font => $Normal_Font,
                                     -command =>\&sub_insert,
                                       -width => '15')-> pack(
                                        -side => 'left'); 

        #text area definition
        $input_text_1 = $sub_frm_insert->Text(-foreground => "black",
                                     -background => "grey",
                                          -width => "37",
                                         -height => "2" )->pack(
                                           -side => 'right');    
     }                  

    }


 # -----------
 # Subroutines 
 # ----------- 


sub sub_insert{

 $insert_fl = $sub_frm_insert->getOpenFile(
              -title=>"Open File",
              -filetypes=>\@types) or return unless(defined($insert_fl));

 my $check_insert = &check_insert_fl($insert_fl);

     if ($check_insert){
           push (@Files, $insert_fl);
           $input_text_1->insert("end", $insert_fl."\n");
               # Only allowed one file
               if (@Files eq 0){
                   $input_btn_1->configure(-state =>'normal');
               }else{                   
                   $input_btn_1->configure(-state =>'disabled');            
               }
            $insert_fl = (); #reset value
            $input_text_1 = ();
            $input_btn_1 = ();
     }else{
          $message_box_warning = $sub_frm_insert->messageBox(
                        -title => "File Error"
                        -message => "The extention should be .txt",
                        -type => "OK",
                        -icon => "error");
         # $insert_fl = (); #Reset Value
          $sub_frm_insert->update;
          return;
     }

 }

当我尝试运行并获取10个文件中的2个时,突然停止并且无法插入更多文件。 有人可以帮我解决这个问题吗?

0 个答案:

没有答案