in reply to noob regexpression question
Your code pushes the entire line onto the array for each match. Is that really what you want? Because that means a line such as the sample you gave causes two elements to be pushed onto the array:
[AlarmForwarderServer.exe,app_common.dll,DsCommon.dll,DSGccCommon.dll, +DsRffCommon.dll,DsGccProxy.dll,DsRffProxy.dll,] AlarmForwarderServer.exe,app_common.dll,DsCommon.dll,DSGccCommon.dll,D +sRffCommon.dll,DsGccProxy.dll,DsRffProxy.dll,
If your goal is to have a list of dlls associated with each exe, then you should split each line on commas first. The resulting list of strings you can push onto an array:
my @dllarray = map { chomp; [ split /,/ ] } @exeDllLines; # iterate over the collected data: for ( @dllarray ) { my( $exe, @dlls ) = @$_; print "$exe uses the following DLLs:\n"; print "$\t$_\n" for @dlls; }
However, a more robust solution would use a hash:
my %exeDll; for ( @exeDllLines ) { chomp; my @a = grep /\S/, split /,/; # split on comma; filter out emp +ty fields my @dlls = grep /\.dll$/, @a; # get list of dll files for my $exe ( grep /\.exe$/, @a ) { @{$exeDll{$exe}}{@dlls} = () # OR: $exeDll{$exe}{$_}++ for @dlls; } } # then you can iterate over the collected data: for my $exe ( sort keys %exeDll ) { print "$exe uses the following DLLs:\n"; for my $dll ( sort keys %{ $exeDll{$exe} } ) { print "\t$dll\n"; } }
|
|---|