Perl: UNIX環境変数を全て展開
正規表現とENVハッシュの組み合わせで実現できる。
1 2 3 4 5 6 | sub expand { my ( $text ) = @_ ; $text =~ s{ \$ {? (\w+) }? } { exists $ENV { $1 } ? $ENV { $1 } : $& }gexms; return $text ; } |
参考:
http://stackoverflow.com/questions/7697216/perl-one-liner-to-expand-unix-environment-variables
0 件のコメント:
コメントを投稿