jack64 has asked for the wisdom of the Perl Monks concerning the following question:

Hi perl Monks, Im trying to debug some issues and im got stuck...the script below is integrated with a software.... The below will give list of log files($covLogPathname.$suff) in a directory.. i have tried tp123.log and tp_123.log for filenames and im not able to get it printed (Found coverage output $covLogPathname.$suff\n";)

my @coverageLogPathnames; # First, look for files of the form tpxxx/tpxxx.log: use File::Find; my @testDirs; my $testsDir_mixed = ToMixed::PathToMixed( $testsDir ); find( sub { push @testDirs, $File::Find::name if -d && /tp_\w+/i }, +$testsDir_mixed ); foreach (@testDirs) { m{^(.*)/(tp_\w+)}i; my ($pathPrefix,$tpname) = ( $1 ? ($1,$2) : ('.',$_) ); my $covLogPathname = "$pathPrefix/$tpname/$tpname"; #print STDERR " // No coverage-logs/hitmaps fou +nd in test chekcing $covLogPathname\n" unless $found; my $found = 0; foreach my $suff ('log', 'bin', 'txt', 'dat') { my $mixed = ToMixed::PathToMixed( "$covLogPathname" ); print STDERR " // No coverage-logs/hitmaps fo +und in test chekcing $mixed\n" unless $found; if ( -e "$mixed" ) { push @coverageLogPathnames, "$covLogPathname.$suff"; print STDERR " // Found coverage output $covLog +Pathname.$suff\n"; ++$found; $foundone = $found; } } print STDERR " // No coverage-logs/hitmaps found in test su +bdirectory $pathPrefix/$tpname\n" unless $found; }

The below one is giving results but only for certain no of log files...for eg if there are 50 log files only 29 or 30 , im able to get....

if ($foundone == 0) { # New option: search under the hitmaps-direct +ory (one level only, any name in front) my $covLogPathname = "$testsDir"; my @hitfiles; my $covLogPathname_mixed = ToMixed::PathToMixed( $covLogPathname + ); find( sub { push @hitfiles, $File::Find::name if -f }, $covLogPa +thname_mixed ); foreach (@hitfiles) { my $foundfile = $_; my ($base,$path,$suff) = fileparse( $foundfile, "\.(log|bin| +txt|dat)" ); if ($suff ne "") { push @coverageLogPathnames, "$foundfile"; print STDERR " // Found coverage output $foundfil +e\n"; } } }

The below script also doesnt return any result..

# Second, look for logs named hitmap.(log|bin|txt): find( sub { if (-f && /^[-\w]*hitmap[-\w]*\.(log|bin|txt|dat)$/i) { push @coverageLogPathnames, $File::Find::name; print STDERR " // Found coverage output $File::Find +::name\n"; } }, $testsDir_mixed ); print STDERR " // Found coverage output hi4"; print STDERR " // Number of coverage logs found: ", (@coverageLog +Pathnames+0), "\n"; return \@coverageLogPathnames; }

im not strong in perl and im trying to debug the above but im not able to...please help monks..thanks.. $covLogPathname - directory where the log files are kept....

Replies are listed 'Best First'.
Re: Debuging Perl Script
by toolic (Bishop) on May 08, 2013 at 17:25 UTC
    You should make sure the regex matches before using captured values:
    if (m{^(.*)/(tp_\w+)}i) { my ( $pathPrefix, $tpname ) = ( $1 ? ( $1, $2 ) : ( '.', $_ ) ); # etc... }

    Take a look at the Basic debugging checklist for other generic advice.