thundergnat has pointed out the problem with the accidental globbing. I think you can make the code simpler and easier to read if you dispense with the intermediate @dir_list variable because you can autovivify each array directly. I have used while (<DATA>) {...} to read into $_ so that matches and the chomp are less cluttered. I think I'm right in saying (and I'm sure I'll be corrected if I'm wrong) that the foreach will also read the entire file in order to build a list that it can iterate over; possibly not what you want.

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.