Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EVAL command not executing

Status
Not open for further replies.

hubud

Instructor
Oct 18, 2002
123
GB
Hi,

Sorry about the load of code below but I though I'd best include as much as I can.

The script is peppered with print() commands to troubleshoot and i've found the only part thats not working is when it tries to enter the EVAL block towards the end.

If anyone has any ideas much appreciated.

# @(#) Script that checks last 150 session log files for any failures or errors and reports details to Production support.
# Usage: cs takes the switch "-m". This will mail, rather than report to stdout(the deault), the user calling the script.


my $scripts='/users/$USER';
my $space = " ";
my $dir = '/apps/informat5/informatica/PowerCenter/SessLogs';
my $temp = '/users/msimcox/temp';
my $time = gmtime;
my @pr_list = ();
my @pr_files = ();
my @matchlist = ();
my @matches = ();

chomp(my @matchlist = ( '^ORA',
'No such file or directory',
'failed to extend rollback segment',
'Error executing shell command...$',
'Error connecting to database...$',
'Error initializing DTM for session...$',
'An error occurred while connecting',
'TNS:could not resolve service name',
'fetched column value was truncated',
'unexpected end of SQL command',
'Received request to stop session run',
'missing expression',
'Failed to logon to Database server',
'Deadlock error encountered.',
'table or view does not exist',
'STG_PROD.CHECK_SESSION',
'failed to extend rollback segment',
'resource busy and acquire with NOWAIT specified',
'Joiner will not produce any output row'
));

@matches = map { qr/$_/ } @matchlist;

chdir "$dir" or die "Can't chdir to SessLogs: $!";
chomp(my @srcfiles = `ls -1rt | tail -170`);


foreach my $file (@srcfiles) {

my $curfile = `tail -1 $file`;

push (@pr_files, $file) if $curfile =~ /Session run completed with failure/

}


#HEADER INFORMATION

&pl("\n\tAUTOMATED SESSION LOG SEARCH RESULTS\n\t------------------------------------\n\nFiles scanned 170 Directory: $dir $space Time: $
time\n\n");


#Bare block for perl variable alteration
#Push failures onto @temp array
{
local $" = '|';
my @temp = ("Just to hold a value\n");
my @i;
print "@matches";
foreach my $file (@pr_files) {
print "Entered the file read loop\n";
open FILE, "$file" or die "Cant open file: $file";
print "Opened file $file\n";

&pl ("$file failed");
print "About to study file $file\n";
#Bare block for perl variable alteration
{
local $/ = undef;
print "Entered study section for file: $file\n";
my $hndlread = <FILE>;
study ($hndlread);
close FILE;

}
print "Left study section for file: $file\n";

#@temp = (); #reset @temp to nothing for new file

$i = 0;
print "Value held by counter i: $i.\n";

### DOES NOT ENTER EVAL COMMAND ????? ###############

eval { $hndlread =~ /(@matches)
print "Made it to the eval block\n";
(?{
print $1;
foreach (@temp) {
$i++ if ($_ eq $1);
}

push @temp, $1 if ($i = 0);

})
/gx
}

#######################################################

}
print "About to print temp array within block.\n";
foreach (@temp) {
print;
print "Entered loop to print off temp array.\n";
}

}
print "Left file read loop.\n";

&output;



#####Start of subroutines#####################

sub pl {

push @pr_list, "$_[0]";
}

sub output {
foreach (@pr_list) {
print "$_\n";
}
}


cheers

simmo
 
It looks like a syntax error on the Eval block itself.

Code:
eval {  $hndlread =~ /(@matches)[COLOR=red]/)[/color]

Try this instead and see what happens.
 
Still not getting anything. I've made some changes and have found i'm getting the following error

Use of uninitialized value in pattern match (m//) at check_session.pl line 90.

This refers to the line:

eval { $hndlread =~ /(@matches)

Also I'm not sure about it being syntax in the eval. I've set "use warnings" and don't get anything.

Also, whole match block is:

$hndlread =~ /(@matches)
print "Made it to the eval block\n";
(?{
print $1;
foreach (@temp) {
$i++ if ($_ eq $1);
}

push @temp, $1 if ($i = 0);

})
/gx

as far as I'm aware the /x at the end means ignore spaces!



cheers

simmo
 
First, I think you need a semicolon after the last } of the eval.
Second, what is it exactly you're trying to do with this eval?

 
tried the ";" after the eval and still nothing.

The piece of code in the eval block is designed to check the contents of $hndlread for each value in the array @matches, which is declared at the top of the script outside the eval block.

So for each value in @matches if it finds that string in the slurped variable $hndlread it adds the matched string ($1) to the @temp array. it then continues looking, if it comes across the same match it attempts to find the same match in @temp. If it finds a match it won't push it to @temp, if not it pushes it. When a match is added it increments $i, so if it has matched already in the search $i will be = 1 or more, so it won't push it to @temp.
It does this for each possible list in the @matches array. as the matches array = (val1|val2|val3) etc.

After this process completes the @temp array should contain list of the string matches found in $hndlread from the @matches array. At the end of the script @temp is printed off so a list of values, these will be error conditions found in a file, are seen by the user in a report.

I'm pretty sure the logic is ok, maybe not otherwise it would work.

There are "print" all through this so I can troubleshoot but nothing gets printed in the eval block and the @temp array prints off empty.

might be trying to be too clever, any suggestions on making this easier.



cheers

simmo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top