開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、13章(ディレクトリ操作)の13.13(練習問題)3.を解いてみる。
その他参考書籍
13.13(練習問題)3.
コード(BBEdit, Emacs)
sample289_3.pl
#!/usr/bin/env perl
use strict;
use warnings;
use 5.016;
use utf8;
binmode STDIN, ':utf8';
binmode STDOUT, 'utf8';
binmode STDERR, 'utf8';
print 'ディレクトリ名を入力: ';
chomp (my $dir_to_process = <STDIN>);
if ($dir_to_process =~ /\A\s*\Z/) {
chdir or die "cannot chdir to home directory: $!";
} else {
chdir $dir_to_process or die "cannot chdir to $dir_to_process: $!";
}
for (sort glob '.* *') {
say $_;
}
入出力結果(Terminal)
$ ./sample289_3.pl ディレクトリ名を入力: . .. .CFUserTextEncoding .DS_Store .Trash .bash_history .dropbox .dropbox-master .emacs .emacs.d .emacs.el~ .emacs_bash-4.2 .emacs~ .ghc .profile .python_history .ssh Desktop Documents Downloads Dropbox Library Movies Music Pictures Public Sites $ ./sample289_3.pl ディレクトリ名を入力: . . .. sample289_1.pl sample289_1.pl~ sample289_2.pl sample289_3.pl sample289_3.pl~ $ ./sample289_3.pl ディレクトリ名を入力: / . .. .DS_Store .DocumentRevisions-V100 .MobileBackups .Spotlight-V100 .Trashes .dbfseventsd .file .fseventsd .vol Applications Library Network System Users Volumes bin cores dev etc home mach_kernel net opt private sbin tmp usr var $
0 コメント:
コメントを投稿