有沒有更好的方法來使用正則表達式捕獲分組編寫下面的代碼?Perl正則表達式捕獲分組
我期待在錄製後立即獲取文件夾名稱。
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $path1 = '\\server1\Recordings\AU-AR-Online\Outbound\20160120\52031\52031-14-07-16.wav';
my $path2 = '\\server2\e$\Recordings\SU-AC-Online\Outbound\20160120\52031\52031-14-07-16.wav';
my @paths = ($path1,$path2);
foreach my $path (@paths) {
# Split path into fields
my @array = (split /\\/, $path);
# Get index of Recordings
my($index)= grep { $array[$_] eq "Recordings" } 0..$#array;
# Brand always follows Recordings
print $array[$index+1];
}