Reputation: 144
I am working on implementing something where i need to check whether value of a variable is defined or not and then proceed with exiting the code. I kept this logic in one script where it has to check for all files opened on my perforce client.
eval { $test = $temp->project($loc); };
unless ($test){
print "undefiled value.please check.\n\n";
exit(1);
}
There are other files which are opened on my perforce client which needs to be validated. Here my script gets exiting when it sees first issue. Here i want to display all the issues by validating all opened files on my client. Any suggestions?
Upvotes: 0
Views: 59
Reputation: 69264
I guess you'd want to change the code to something like this:
# Before your loop, set up a variable to store errors
my @errors;
# Where your code is
eval { $test = $temp->project($loc) };
unless ($test) {
# Don't exit, but store the error and move to the next iteration
push @errors, "Undefiled value <$loc>. Please check.\n\n";
next;
}
# After your loop, die id there are any errors
die join "\n", @errors if @errors;
Update: I like ikegami's suggestion in the comments.
# Before your loop, set up a variable to count errors
my $errors;
# Where your code is
eval { $test = $temp->project($loc) };
unless ($test) {
# Don't exit, but store the error and move to the next iteration
warn "Undefiled value <$loc>. Please check.\n\n";
++$errors;
next;
}
# After your loop, die id there are any errors
exit(1) if $errors;
Upvotes: 1