開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Strawberry Perl (WindowsのPerlの言語処理系)
- Visual Studio Code (Text Editor)
- Perl 5.28 (プログラミング言語)
初めてのPerl 第7版 (Randal L. Schwartz(著)、brian d foy(著)、Tom Phoenix(著)、近藤 嘉雪(翻訳)、嶋田 健志(翻訳)、オライリージャパン)の13章(ディレクトリ操作)、13.4(練習問題)5の解答を求めてみる。
コード
#!/usr/bin/env perl use strict; use warnings; use utf8; use v5.18; use File::Spec; say '5.'; my ($old, $new) = @ARGV; $new = File::Spec->catfile($new, $old) if -d $new; rename $old, $new or warn "can't rename $old to $new: $!";
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ ls
./ ../ a.txt sample5.pl*
$ mkdir tmp
$ tree
.
├── a.txt
├── sample5.pl
└── tmp
1 directory, 2 files
$ ./sample5.pl a.txt b.txt
5.
$ ls
./ ../ b.txt sample5.pl* tmp/
$ ./sample5.pl b.txt tmp
5.
$ ls
./ ../ sample5.pl* tmp/
$ tree
.
├── sample5.pl
└── tmp
└── b.txt
1 directory, 2 files
$
0 コメント:
コメントを投稿