Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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"); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090224]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-06-24 15:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.