2020年5月25日月曜日

開発環境

初めてのPerl 第7版 (Randal L. Schwartz(著)brian d foy(著)Tom Phoenix(著)近藤 嘉雪(翻訳)嶋田 健志(翻訳)、オライリージャパン)の12章(ファイルテスト)、12.5(練習問題)1の解答を求めてみる。

コード

#!/usr/bin/env perl
use strict;
use warnings;
use v5.28;

foreach (@ARGV) {
    say "ファイル名: $_";
    unless (-e $_) {
        say "存在しない";
        next;
    } 
    say "読み出し可能" if -r _;
    say "書き込み可能" if -w _;
    say "実行可能" if -x _;
}

入出力結果(Zsh、PowerShell、Terminal)

% mkdir temp
% touch temp/temp{1,2,3,4,5}.txt
% chmod 0 temp/temp2.txt 
% chmod a+x temp/temp3.txt 
% chmod a+w temp/temp4.txt 
% chmod a+r temp/temp4.txt
% ./sample1.pl temp/* aaaaa
ファイル名: temp/temp1.txt
読み出し可能
書き込み可能
ファイル名: temp/temp2.txt
ファイル名: temp/temp3.txt
読み出し可能
書き込み可能
実行可能
ファイル名: temp/temp4.txt
読み出し可能
書き込み可能
ファイル名: temp/temp5.txt
読み出し可能
書き込み可能
ファイル名: aaaaa
存在しない
% 

0 コメント:

コメントを投稿