Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: when i try to execute another scripts if fails

by Anonymous Monk
on Jun 17, 2014 at 23:53 UTC ( #1090224=note: print w/ replies, xml ) Need Help??


in reply to when i try to execute another scripts if fails

Remember Re: check to see if a file has todays data in it, if it has exit if not then add data? Why don't you write code that way?

#!/usr/bin/perl -- use strict; use warnings; use POSIX qw/ strftime mktime /; Main( @ARGV ); exit( 0 ); sub Main { ... if( FileUpdatedToday( $filename ) ){ print "\ file has already been updated today"; } else { UpdateFile( $filename ); } if( not -s $temp ){ EmailReport( $temp ); } } sub EmailReport { my( $temp ) = @_; exec $^X, $emailPL, or die "problem with $emailPL"; } sub FileUpdatedToday { ... return !!1; .. return !!0; } sub UpdateFile { ... }

Its easier this way to figure out your logic, to reason about when/what should happen, and you can even write simple tests to make sure each part works the way you want

sub TestFileUpdatedToday { require Test::More; Test::More->import( tests => 4 ); PrepareTestfiles('testfiles'); my $notexist = 'testfiles/notexist'; my $empty = 'testfiles/empty'; my $stale = 'testfiles/stale'; my $updated = 'testfiles/updated'; for my $file ( $notexist , $empty, $stale ){ ok( ! FileUpdatedToday( $file ), "FileUpdatedToday( $file ) sh +ould not be true"); } ok( FileUpdatedToday( $updated ), "FileUpdatedToday( $updated ) sh +ould be true"); }


Comment on Re: when i try to execute another scripts if fails
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2015-07-30 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls