開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『初めてのPerl 第5版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-427-9) の13章(ディレクトリ操作), 13.14(練習問題)7を解いてみる。
7.
やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))
コード(TextWrangler)
#!/usr/bin/env perl use strict; use warnings; use File::Basename; use File::Spec; my $o = $ARGV[0] eq '-s'; shift @ARGV if $o; my($old, $new) = @ARGV; if(-d $new){ my $basename = basename $old; $new = File::Spec->catfile($new,$basename); } if($o){ symlink $old, $new or warn "can't symlink $old to $new: $!\n"; } else { link $old, $new or warn "can't link $old to $new: $!\n"; }
入出力結果(Terminal)
$ cat test A a kamimura's blog http://sitekamimura.blogspot.com KMI http://www.mkamimura.com Fred FRED fred frederick Alfred fred flintstone Mr. Slate Mississippi Bamm-Bamm wilama barney wilma and fred fred and wilma Wilma and Fred Fred and Wilma wilma&fred Mrs. Wilma Flintstone I saw Wilma yesterday I, Wilma! Z llama $ ./perl_program -s test test_new $ cat test_new A a kamimura's blog http://sitekamimura.blogspot.com KMI http://www.mkamimura.com Fred FRED fred frederick Alfred fred flintstone Mr. Slate Mississippi Bamm-Bamm wilama barney wilma and fred fred and wilma Wilma and Fred Fred and Wilma wilma&fred Mrs. Wilma Flintstone I saw Wilma yesterday I, Wilma! Z llama $ ls test* test test.bak test_link test_new test_folder: test
シンボリックリンクであることを確認できた。(右画像)ハードリンクのときと違ってアイコンに矢印有り。
0 コメント:
コメントを投稿