Below is my progress so far. Below script is going through each file in a directory and printing all lines that has dbms output string in them. But how to eliminate dbms output string which is in between commented lines block. Ex:

/*Line 1 Line 2 Line 3 dbms out put string Line 4 */
I want to ignore above 5 lines
#!/usr/bin/perl use File::Find; use File::Basename; use strict; use English; # to get program name use Cwd; #use warnings; # Variables definitions my $match_param = "DBMS_output.put_line"; my $ignore_parameter = "/*"; undef my @nocomment_array; # array for not commented line undef my @comment_array; # array for commented line undef my @file_list; undef my @filenames; # list of filenames which contains matching para +meter my $file_list_ref; my $dir = cwd; #current working directory @ARGV = $dir unless @ARGV; find(\&process_file,@ARGV); foreach my $file(@$file_list_ref) { next if $file =~ m/$PROGRAM_NAME/i ; chomp($file); open(FH,"<$file") or die "Couldn't open $file for reading: $!\n"; my $line = 0; while(<FH>) { chomp $_; $line = $line +1; if (($_=~ m/$match_param/i) && ($_ !~ m/\s*--\s*$match_par +am/i)|| ($_=~ m/$match_param/i) && ($_ !~ m/$ignore_parameter\s*$matc +h_param/i)) { push(@nocomment_array,"$line\t$_\n"); } } if (@nocomment_array) { push(@filenames,"$file\n") if defined $nocomment_array[0]; print "\n$file\n" if defined $nocomment_array[0]; print @nocomment_array if defined $nocomment_array[0]; } undef @nocomment_array; } my $count = scalar(@filenames); print "\n###################################\n"; print "List of $count files in the above output\n"; print "###################################\n"; print @filenames; # Print only the filenames (the whole directory pat +h) # # process_file() subroutine: Processes all files of a directory recurs +ively # sub process_file() { next unless !-d $File::Find::name; # skips directory my $temp = $File::Find::name; chomp($temp); my $file_name = basename($temp); # strips filename if ($file_name =~ m/.sql$/) { push(@file_list,$temp); } $file_list_ref = \@file_list; } # end of process_file()

In reply to Re^2: How do i search and extract commented lines from a file using perl? by sravan937
in thread How do i search and extract commented lines from a file using perl? by sravan937

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.