Hello hoping someone could help me. I am trying to create a script which searches through all files in a directory for a string, if the string is found I want it to look through the entire file which it found the first string and look for a second string. Right now I have the code below, but it looks like when it tries to match the second string it's comparing the regex against the result/output of the first regex not against the entire file which it found the fist regex in.
How can I make my script search for a string against a file if it finds the string in that file then search that entire file once again for the second string.
thanks for the help.
<code>
sub edits() {
if ( -f and /^Khlog.08$/ ) {
foreach ( $File::Find::name ) {
open(LOG, "< $File::Find::name") or die "Could not open fi
+le $_: $!";
while ( <LOG> ) {
my $LINE = $_;
if ( $LINE =~ m/002389983/ ) {
print "Looking for: 002389983\n Found it in file:
+$LINE\n";
if ( $LINE =~ m/29994339499/ ) {
print "Looking for: 29994339499\n Found it in
+file: $LINE\n";
}
else {
print "Could not find the second string: 29994
+339499\n";
}
}
}
}
}
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.