I've been trying to solve this problem that I've been having with a conditional using RegEx. the code is as follows

while (my $curline = <IN>){ #if the current line read is a domain #domain if ($curline =~ /^#/){ print $curline, "\n"; # for debugging my $currentdomain = $curline; while($curline = <IN>){ if ($curline !~ /^#\s/ or $curline !~ /^\s/) { $server++; $currentserver = $curline; push(@serverlist, $currentserver); } ## end if elsif ($curline !~ /^\s/){ $HoA{$currentdomain} = [@serverlist]; $currentdomain = $curline; } #end else } ## end while if ( eof(IN)){$HoA{$currentdomain} = [@serverlist];} } ## end if } ## end while

Let's say I have a list domain and servers in the following format : # domain 1 servera serverb # domain 2 serverc serverb What i wanted this little piece of code to do was to have of hash of arrays with the servers assigned for each domain assigned to arrays and the domains stored into each element of the hash table with the array of servers associated with each element of the hash table. (it's 1:28 a.m and if i sound incoherent, i'm tired :) ) What actually is going on is that the first domain is actually being stored in the hashtable, however the 2nd domain is being stored in the array that's associated with the first domain. Is there a problem with my RegEx conditional? If so, where did I go wrong? Any help is greatly appreaciated. Thanks

In reply to Quarms with RegEx by TraderX

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.