I have left the chomp until after rejecting the comment lines; no point in doing work on something we're going to throw away. You don't need to escape the equals in the match and I'm not sure why you were capturing the equals signs either side of the server name; perhaps there was a reason that has been lost as you reduced the code for your post.
use strict; use warnings; use Data::Dumper; my $rec = q{}; my %HoA = (); while (<DATA>) { next if m{^#}; chomp; if (m{^==(\w+)==}) { $rec = $1; } else { push @{$HoA{$rec}}, $_; } } print Data::Dumper->Dump([\%HoA], ['*HoA']); print qq{\n}; foreach my $server (keys %HoA) { foreach my $unc (@{$HoA{$server}}) { print qq{$server: $unc\n}; } } __DATA__ ########## Server 1 UNC's ######################## ==SERVER1== \\server1\share1\tld0\sub-dir1\sub-dir2 \\server1\share1\tld0\sub-dir2\sub-dir2 \\server1\share2\tld1\dir1\subdir2\subdir3 \\server1\share2\tld1\dir1\subdir2\subdir4 ########## Other Server UNC's ######################## ==REMOTESERVER1== \\remoteserver1\share1\tld1\dir1\subdir2\subdir4 ==REMOTESERVER2== \\remoteserver2\share1\tld1\dir1\sub dir 3\sub dir 5\report's \\remoteserver2\share1\tld1\dir2\sub dir 4\sub dir 6\reports ###### No Entries Below This Line ######
Here's the output. Note that Data::Dumper does it's own escaping when serializing the data.
%HoA = ( 'REMOTESERVER1' => [ '\\\\remoteserver1\\share1\\tld1\\dir1\\ +subdir2\\subdir4' ], 'SERVER1' => [ '\\\\server1\\share1\\tld0\\sub-dir1\\sub-dir2 +', '\\\\server1\\share1\\tld0\\sub-dir2\\sub-dir2 +', '\\\\server1\\share2\\tld1\\dir1\\subdir2\\sub +dir3', '\\\\server1\\share2\\tld1\\dir1\\subdir2\\sub +dir4' ], 'REMOTESERVER2' => [ '\\\\remoteserver2\\share1\\tld1\\dir1\\ +sub dir 3\\sub dir 5\\report\'s', '\\\\remoteserver2\\share1\\tld1\\dir2\\ +sub dir 4\\sub dir 6\\reports' ] ); REMOTESERVER1: \\remoteserver1\share1\tld1\dir1\subdir2\subdir4 SERVER1: \\server1\share1\tld0\sub-dir1\sub-dir2 SERVER1: \\server1\share1\tld0\sub-dir2\sub-dir2 SERVER1: \\server1\share2\tld1\dir1\subdir2\subdir3 SERVER1: \\server1\share2\tld1\dir1\subdir2\subdir4 REMOTESERVER2: \\remoteserver2\share1\tld1\dir1\sub dir 3\sub dir 5\re +port's REMOTESERVER2: \\remoteserver2\share1\tld1\dir2\sub dir 4\sub dir 6\re +ports
I hope this is of use.
Cheers,
JohnGG
In reply to Re: Windows Paths
by johngg
in thread Windows Paths
by nimdokk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |