use strict; use warnings; >snip< sub new_date { my ( $year, $month, $day ) = (localtime)[ 5, 4, 3 ]; sprintf( "%04d%02d%02d", ( $year += 1900 ), $month + 1, $day ); } $passed_new_date = new_date(); sub new_date_append { return $monster_date = "OhioS$passed_new_date"; } $fref = \&new_date_append(); ###--- HERE is my REF ---### >snip< if ( $passed_new_date and $$fref ) { calls 2 subs.... } #### use strict; use warnings; use Net::FTP; use MIME::Lite; my ( $ftplog, $fref ); my $OHMONSTER; my $RENAMED = q/OhioS.xml/; my ( $monster_date, $passed_new_date ) = 0; my $overide = $SIG{__DIE__}; ## get error handler currently assigned to die() $SIG{__DIE__} = sub { my $error = shift; ## error now holds the mesg passed to die $overide->($error) if ( ref $overide ); mailme($error); }; sub new_date { my ( $year, $month, $day ) = (localtime)[ 5, 4, 3 ]; sprintf( "%04d%02d%02d", ( $year += 1900 ), $month + 1, $day ); } $passed_new_date = new_date(); sub new_date_append { return $monster_date = "OhioS$passed_new_date"; } $fref = \&new_date_append(); sub mailme { my $error = shift; my $msg = MIME::Lite->new( From => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx>', To => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx>', To => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx>', Subject => "HRIS FTP Inbound to monster.com had problems and or failed:\t\t$error", Type => 'multipart/related' ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$ftplog", Filename => "$ftplog" ); $msg->send; } ## Delete files older than 12 days sub filetest { my $e = 0; my @diraray = glob("/psofthr/hr88prd/intf/monster/inbound/*"); foreach $e (@diraray) { if ( -M $e > 12 ) { unlink $e; } } } sub ftpme { my $remotehost = "ftp.monster.com"; my $remotedir = "xxxxxxx"; my $localdir = "/psofthr/hr88prd/intf/monster/inbound"; my $user = "xxxx"; my $pass = "xxxx"; $ftplog = "/psofthr/hr88prd/intf/monster/log/interface_monster.log"; open( FTPLOG, ">>$ftplog" ) || warn "Could not open FTPLOG FH $!"; my $ftp = Net::FTP->new( $remotehost, Debug => 10 ) || die "Failed to connect to $remotehost: $!", print FTPLOG "\n$passed_new_date\nFailed to connect to $remotehost!"; print FTPLOG $passed_new_date; $ftp->login( $user, $pass ) || die "Login failed at $remotehost!: $!", print FTPLOG "\n$passed_new_date\nLogin Failed at $remotehost!"; $ftp->binary(); $ftp->cwd($remotedir) || die "CWD to folder outbound failed!: $!", print FTPLOG "\n$passed_new_date\nCWD to folder outbound failed!"; foreach ( $ftp->ls() ) { if (/${$fref}\d+\w+/) { $OHMONSTER = $_; $ftp->get( $OHMONSTER, "$localdir/$OHMONSTER" ) || die "FTP get from monster.com failed!: $!", print FTPLOG "\nFTP get at monster.com failed!"; sleep 2; $ftp->delete($RENAMED) || die "FTP dele of existing file at monster.com failed! : $!", print FTPLOG "\nFTP dele at monster.com failed!"; sleep 2; $ftp->rename( "$OHMONSTER", "$RENAMED" ) || die "FTP rename at monster.com failed!: $!", print FTPLOG "\n$passed_new_date\nFTP rename at monster.com failed!"; print FTPLOG $passed_new_date; last; } } $ftp->quit; close(FTPLOG) || warn "was unable to close FTPLOG FH $!"; } if ( $passed_new_date and $$fref ) { ftpme(); filetest(); } else { my $error = 'variables for FTP rename at monster.com were not set, rename will not work & process will fail!'; mailme($error); }