I am attempting to open up a file in the following format: The first word is the item to search for and the second is the new search term I want printed. EX: skin -new skin The second thing I want is to open up the file that is to be searched. If the search item above appears anywhere in the file then I want the new search term printed to another file. Can anyone tell me why this regular expression is not matching?  if  ($line =~ /$term)/i) { Below is the entire code:

my $dir = 'c:/perl_scripts/testing'; my $fsearch = "$dir/input.txt"; my $ssearch = "$dir/isearch.txt"; my $countsection = 1; my $count = 0; my $line; # Opens file with search items open (OFILE,"<$ssearch")||die "Could not open input file isearch.txt\n +"; # Opens file with list of files to be searched open (INFILE,"<$fsearch")||die "Could not open input file input.txt\n" +; while($sitem = <OFILE>) { chomp $sitem; @newterm = split (/\-/, $sitem); $term = $newterm[0]; while($sigfile = <INFILE>){ chomp $sigfile; open (TEXTFILE, "<$dir/$sigfile") || die "\nCAN'T OPEN $fsearc +h\n"; #Create NEW File to output Revised Data open(COMBINE_FILE, ">>$dir/REVISE_$sigfile")|| die "\nCAN'T OPEN R +EVISE_$sigfile\n"; while($line = <TEXTFILE>) { chomp $line; my @sepdata = split (/\s+/, $line); if($sepdata[0] eq "+") { $countsection++; } #Prints out top of file to a new external file with no modifications a +nd adds new "pool term" to the end of section 2 if ($countsection <= 3){ print COMBINE_FILE "$line\n"; } if ($line =~ /$term)/i) { if ($countsection > 3 && $sepdata[0] eq "+" ) { print COMBINE_FILE "$newterm[1]\n"; } } if ($countsection > 3) { printf COMBINE_FILE "%-3s", $sepdata[0]; printf COMBINE_FILE "%3s ", $sepdata[1]; printf COMBINE_FILE "%-10s", $sepdata[2]; printf COMBINE_FILE "%4s", $sepdata[3]; printf COMBINE_FILE "%5s ", $sepdata[4]; printf COMBINE_FILE "%3s ", $sepdata[5]; printf COMBINE_FILE "$sepdata[6]\n"; } } } }

READMORE tags added by Arunbear


In reply to trouble matching by cravena

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.