nimdokk has asked for the wisdom of the Perl Monks concerning the following question:
My code so far (streamlined to display problem):
use File::Spec; use Data::Dumper; use strict; use warnings; my @dir_list; my $rec; my %HoA; foreach my $dir (<DATA>) { chomp $dir; my $first=substr($dir,0,1); if ($first =~ /#/) { next; } elsif ( $first =~ /=/ ) { if ($dir=~/(^\={2})(\w+)(\={2})/) { $rec=$2; } @dir_list=(); #reset the list of directories to empty } else { $dir=File::Spec->catdir("\'$dir\'"); push @dir_list, $dir; #add directory name to array $HoA{$rec}=[ @dir_list ]; #add array of directories to + HoA }#close if }#close foreach ###################################################################### +####################################### print Data::Dumper->Dump([\%HoA], ['*HoA']); for my $server ( keys %HoA ) { chomp $server; for my $dir ( <@{ $HoA{$server} }> ) { chomp $dir; print "$server: $dir\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 ######
%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\share1\tld1\dir2\sub dir 4\sub dir 6\reports'
What I expect to see in the output would be something along the lines of:
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
Any thoughts on working through this issue would be appreciated. I have tried wrapping single and double quotes around the UNC's, flipping the backslashes to forward slashes and nothing really seems to work (a few things make it worse such as removing the directory seperators completely).
update: figured out the problem as thundergnat points out below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Windows Paths
by thundergnat (Deacon) on Jan 17, 2007 at 20:44 UTC | |
by nimdokk (Vicar) on Jan 17, 2007 at 21:00 UTC | |
|
Re: Windows Paths
by johngg (Canon) on Jan 17, 2007 at 21:40 UTC |