Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Lv 5
? asked in 電腦與網際網路程式設計 · 2 decades ago

用 perl 語言寫一個選單去選擇我要開啟的檔案

我想要用 perl 語言寫一個選單去選擇我要開啟的檔案,如:在 C 槽的 EXCEL 目錄下我有許多 .xls 的檔案 ( C:\\Excel\\*.xls )C:\\Excel\\1.xlsC:\\Excel\\2.xlsC:\\Excel\\3.xlsC:\\Excel\\4.xlsC:\\Excel\\5.xls然後我要用 perl 語言寫一個選單:==========選單==========請選擇要開啟的檔案:    1    2    3    4    5==========選單==========  然後只要選擇 1,2,3,4,5 其中一個選項就可開啟相對應的 .XLS 檔案請問要怎麼做,謝謝!

2 Answers

  • 2 decades ago
    Favorite Answer

    #設定 excel 執行檔位置

    $excel_path = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";

    $path = "C:\\Excel\\";

    $extention = "xls";

    opendir( DIR, $path )

    or die "Can't open $path: $!";

    @FILE_LIST = grep{/\.$extention$/} readdir(DIR);

    closedir( DIR );

    print "==========選單==========\n";

    print "請選擇要開啟的檔案\n";

    $i = 1;

    foreach $file (@FILE_LIST) {

    print $i++.": $file\n";


    print "==========選單==========\n";

    $choice = <STDIN>;

    chomp ($choice);

    @args = ($excel_path, $path.$FILE_LIST[$choice-1]);


  • ?
    Lv 5
    2 decades ago



Still have questions? Get your answers by asking now.