Hi Guys,

Need your help with a few modifications in an existing code. I got this code with the help of this forum and would need help in editing this a little bit. This code reads the .opf and .css files in the directory and throws the result if the conditions are met.

use strict; use warnings; use Cwd; my @filedefs = ( { extension => 'css', preaction => sub { $_[0]->{count} = 0 }, testaction => sub { $_[0]->{count}++ }, postaction => sub { print "$_[0]->{label} !! $_[0]->{count} In +stance found\n" }, operations => [ { label => 'Harcoded font size value', test => sub { $_[0] =~ /font-size\s*(:|=)\s*[^%]+$/ } +, }, { label => 'Forced Line height value', test => sub { $_[0] =~ /line-height/ }, }, { label => 'position absolute value', test => sub { $_[0] =~ /position\s*(:|=)\s*absolute/ +}, }, { label => 'Forced font color', test => sub { $_[0] =~ /^\s*color\s*(:|=)/ }, }, ], }, { extension => 'opf', operations => [ { label => 'language', test => sub { $_[0] =~ /language/ }, testaction => sub { print "$_[1]\n" }, }, { label => 'layout or fixed get', test => sub { $_[0] =~ /(pre-paginated|\Qname="f +ixed-layout" content="true"\E)/ }, testaction => sub { $_[0]->{done} = 1 }, postaction => sub { print +( $_[0]->{done} ) ? 'Fixed +layout tag is found' : 'Fixed layout tag is not found', "\n" }, }, ], } ); my $dirpath = getcwd; for my $filedef ( @filedefs ) { my @filepaths = glob( "$dirpath/*.$filedef->{extension}" ); print "\nno $filedef->{extension} files\n" unless @filepaths; for my $filepath ( @filepaths ) { print "\n>>> $filepath <<<\n"; do { $_->{done} = 0; $_->{preaction} // $filedef->{preaction} +// sub { } }->( $_ ) for ( @{$filedef->{operations}} ); open my $filehandle, '<', $filepath or die "could not open '$f +ilepath': $!"; while ( my $line = <$filehandle> ) { # note the below two lines could be handled more efficient +ly in a testaction, which # returns a true or false value to indicate if last etc, b +ecause its unnecessary to check # for every line. my @operations = grep { not $_->{done} } @{$filedef->{oper +ations}}; last unless @operations; chomp $line; do { $_->{test} // sub { 0 } }->( $line ) and do { $_->{te +staction} // $filedef->{testaction} // sub { } }->( $_, $line ) for ( + @operations ) } close $filehandle; do { $_->{postaction} // $filedef->{postaction} // sub { } }-> +( $_ ) for ( @{$filedef->{operations}} ); } } END { print "\nPress enter to exit\n"; <>; }

I want to make the below modifications: 1. Currently, the css and opf file should be place in the directory for the search to happen. If these files are inside the subdirectory then it wont detect these files. I want to modify in such a way that the program can search for files inside the sub directoriesas well. 2. It should read".html" files and should look out for the usage of "svg" tags in it. If found it should dispay that "svg tag has been found in xyz.html" 3. It should read opf for the text "cover". if its found then display cover is found.


In reply to Searching for specific text by mohad

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.