i'm parsing files and trying to find a given variable followed by a dot.
so, the file that i'm parsing is this:
package blah.blah.blah;
import blah.Log;
public void addLeadType(LEAD_TYPE type) {
_leadTypes.add(type);
}
// ** PROTECTED METHODS
// ** PRIVATE METHODS
// ** ACCESSORS
// ** INNER CLASSES
}
and the perl code that i'm using to find a word in that file:
#!/usr/bin/perl
undef $/;
sub fileContainsWord() {
my $file = $_[0];
my $word = $_[1];
my $found = 0;
open FILE, "<$file";
while(<FILE>) {
my $filecontents = $_;
if($filecontents =~ /$word/smg) {
$found = 1;
last;
}
}
close FILE;
return $found;
}
my $file = "SearchSet.java";
my $word = "LEAD_TYPE.";
my $flag = &fileContainsWord($file, $word);
print $flag . "\n";
for some reason, it's not picking up the trailing dot in $word, and flag is coming back '1'
why is this?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.