Perl: UNIX環境変数を全て展開
正規表現とENVハッシュの組み合わせで実現できる。
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 件のコメント:
コメントを投稿