Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have a Perl script that is supposed to monitor a pre-defined list of UNC paths and make sure there are no files waiting to be processed in those directories. The first thing the script does is read in a list of UNC's (in the sample below - from DATA). It then puts these UNC's into a Hash of Arrays (no problem so far - everything work nicely). Next, I want to loop through each of those array's and scan the directory. When I pull the UNC's back out of the array, I run into problems, mainly where the "\\" at the start is escaped down to "\" (I think this is because of the single quote that I am inserting to account for the spaces in the file names). I don't have any control over the names in the UNCs - but if I need to tweak the data a bit to account for spaces and quotes in the paths, I can do that.

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 ######
Here is my output:

%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.


In reply to Windows Paths by nimdokk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-23 14:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found