- PR -

perl question: ".." buster

1
投稿者投稿内容
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2002-01-23 11:17
here's a perl script that normalizes a path by removing ".."
e.g.

$_ = "/usr/lib/perl/../../../junk";
my $re = qr{ ([^/\.]+) / (\.\.) }x;
while ( s{(/$re|$re/)}{}g ) { ; }

(double \ should read single: a known @IT会議室 bug )

can you do the same task using a recursive regex pattern?
Oregon
ベテラン
会議室デビュー日: 2001/08/01
投稿数: 52
お住まい・勤務地: Tualatin 97062
投稿日時: 2002-01-29 04:11
コード:
$re = qr{
    (?<= [/\.]) [^/\.]+ /  # head + glue
    (
        (??{ $re }) /      # nest + glue
    )*
    \.\.                   # tail
}x;


seems working
1

スキルアップ/キャリアアップ(JOB@IT)