Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
XPPErrorLog
#!usr/bin/perl use warnings; use strict; my $filename = 'c:\\Temp\\test.txt'; open(FH, '<:encoding(UTF-8)', $filename) or die "cannot open file $filename"; while(<FH>){ my @tagArray = split('\|', $_); processTag(@tagArray); } close(FH); sub processTag{ my @Tag = @_; my @ErrorMsg; if($Tag[-1]=~m/Yes/g){ my $searchTag = $Tag[0]; my @searchAttr =@Tag[1..scalar @Tag-2]; my $searchContent = getXppContent("C:\\Temp\\out.txt"); if($searchContent eq ''){ print "Cannot get the XPP files\n"; } else{ @ErrorMsg = searchContent($searchTag, $searchContent, @searchAttr); } } writeErrorLog(@ErrorMsg); } sub searchContent{ my ($searchTag, $searchContent, @searchAttr) = @_; #These lines for macros #These lines for Tags my @matches = ($searchContent) =~m/(<$searchTag[^>]+>)/g; my @errMatche; foreach my $attr(@searchAttr){ foreach my $tag (@matches){ if($tag =~m/$attr/g){ if($tag=~m/<fp/){ $tag =~s/\</\[/g; $tag =~s/\>/\]/g; } my $msg = "Check invlaid tag ".$tag." attr $attr\n"; push(@errMatche, $msg); } } } #writeErrorLog(@errMatche); return @errMatche; } sub getXppContent{ my $myFilePath = $_[0]; my $content; open(my $fh, '<:encoding(UTF-8)', $myFilePath) or die "cannot open file $filename"; { local $/; $content = <$fh>; } close($fh); $content=~s/{/</g; $content=~s/}/>/g; return $content; } sub writeErrorLog{ my @error = @_; my $err = join("",@error); print $err; my $outname = 'C:\Temp\log.txt'; if($err=~m/([a-zA-Z]+)/){ #Write Contents in file open(my $fh, '>>:encoding(UTF-8)', $outname) or die "Could not open file '$outname' $!"; print $fh "--------------------------------------------------------------------------------\n"; print $fh $err; close $fh; } }
run
|
edit
|
history
|
help
0
Shalu Kumar
codeyard
Tony Gunk
Array_with_shift_function
Attractive Numbers
Perl basics
perl_tutorial
Simple Perl Interview Question
Perl
Splice