Hello Brothers, I'll preface this question with the honest observation that I think this is a dumb question and I'm embarassed that I've not found a solution but.......I haven't! Is there any way to have a block of code actioned on the right hand side of an or statement? I'm writing a series of subroutines that this is required for and using curly or normal brackets generates compilation errors! If any of these subroutines encounter an error a logfile needs to be updated (using an existing subroutine) and then the return should be actioned (I'm additionally sending the failure message to a generic job logfile - belt AND braces 4 me!). I thought that enclosing this code in a curly brackets block would suffice but alas no.
The following is a wee noddy example of what I'm trying to get to work -
#!/usr/bin/perl -w
#
use strict ;
#
sub toytown {
my $file = 'xxrcblocktest.pl' ;
my $msg = "Unable to open File $file :: $!\n" ;
open INF, "<$file" or print "\n\tmy message\n" ;
print "\n\tActual error :: $!\n" ;
return 0 ;
print "\n\tU shouldn't c this msg!!!!!!!\n" ;
return 1 ;
}
#
my $script = "xxrcblocktest" ;
#
print "\n\t\t<***** Script $script S T A R T S\n" ;
&toytown or die "\n\tError :: $!\n" ;
print "\n\t\t<***** Script $script E N D S\n" ;
With this code if the file doesn't exist the outcome is
my message
Error :: No such file or directory
If the file does exist I get
<***** Script xxrcblocktest S T A R T S
Error ::
Am i just asking a dumb question that you can instantly answer or can't this be done?
Thanks in anticipation,
Ronnie