I have some code that I'm creating and it all works perfectly except for one part. Near the bottom I try to compare if one string matches another from a while loop. If I put in a static string it executes whats inside of the if statement otherwise it doesn't. A note is I didn't list the hash I use in the code but it does work fully.
# Open the inventory file open(HANDLE,"<INVENT.TXT"); while(<HANDLE>) { # Separate each field for a single row @info = split(/,/,"$_"); $code = $info[0]; $description = $info[2]; $manuCode = $info[3]; $retailPrice = $info[9]; $invCount = $info[30]; # Strips out useless characters $code = substr($code,1,length($code)-2); $description = substr($description,1,length($description)-2); $manuCode = substr($manuCode,1,length($manuCode)-2); $retailPrice = substr($retailPrice,1,length($retailPrice)-3); $invCount = substr($invCount,1,length($invCount)-5); # Strips out whitespaces when needed and multiple zeros $code =~ s/\ {1,}//g; $description =~ s/\ {2,}//g; $retailPrice =~ s/0{2,}//g; $invCount =~ s/0{2,}//g; # Converts inventory count to 0 if there is no inventory if($invCount == '') { $invCount = 0; } # Compare the manufacturer code and change it if needed while(($key,$value) = each(%catReplace)) { if($manuCode =~ /$key/) { $manuCode = $value; last; } } # Open the manufacturer file open(MAN,"<file.csv"); while(<MAN>) { # Separate each field for a single row @manInfo = split(/,/,"$_"); $manufacturer = $manInfo[0]; $manuID = $manInfo[1]; # THIS IS WHERE I HAVE PROBLEMS if($manuCode =~ /$manuID/) { $manuCode = $manufacturer; last; } } close(MAN); # Open and write the new inventory list open(NEWFILE,">>test.txt"); print NEWFILE $code.',',$description.',',$manuCode.',',$retailPric +e.',',$invCount."\n"; close(NEWFILE); } close(HANDLE);
Any help would be appreciated.

In reply to Regex problem by Anonymous Monk

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.