in reply to Re: How do i search and extract commented lines from a file using perl?
in thread How do i search and extract commented lines from a file using perl?
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:
I want to ignore above 5 lines/*Line 1 Line 2 Line 3 dbms out put string Line 4 */
#!/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()
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How do i search and extract commented lines from a file using perl?
by stevieb (Canon) on Jun 26, 2015 at 15:45 UTC | |
by BillKSmith (Monsignor) on Jun 26, 2015 at 18:29 UTC | |
Re^3: How do i search and extract commented lines from a file using perl?
by aaron_baugher (Curate) on Jun 26, 2015 at 20:23 UTC |