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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.