Skip to content

Instantly share code, notes, and snippets.

@hiroshi-manabe
Forked from bromne/extract-php-files
Last active December 7, 2016 00:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroshi-manabe/65ceeb308d7008676de451dde07fc958 to your computer and use it in GitHub Desktop.
Save hiroshi-manabe/65ceeb308d7008676de451dde07fc958 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# src/htdocs 下の PHP ファイルのパスを取得して表示します。
# ファイル名が php-files.txt に含まれているもののみ取得します。
# @files は「foo.php」のような PHP ファイル名のリスト,行区切り
open FILE, '<', 'php-files.txt';
chomp(@files = <FILE>);
@file_dict{@files} = (); # ハッシュスライスを使って、%file_dict のキーとして @files の中身を入れる
# *.php
# パイプを使ってみる
open FIND, q{find src/htdocs -name '*.php' |}; # '*.php' はシングルクォートで囲わないとシェルで展開されてしまう
chomp(@paths = <FIND>);
close FIND;
my @php_files = grep {
m{([^/]+)$}; # パス区切り以降をマッチさせる
exists $file_dict{$1};
} @paths;
print join "\n", @php_files;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment