in reply to Re: returns not working
in thread returns not working

Thanks for the reply. I've modified the code per your input. with return 1; it loops back to the: #chomp $_; if ( $id eq $_ ) with just return; it falls out of the subroutine with the error: Use of uninitialized value in numeric eq (==) at esdeploy_new.pl line 184 Calling the code with: *$currentid = SMITHJO* and @deployedfile contains SMITHJO and SMITHJA*
if ( CheckDeployed( $currentid ) == 0) { # do something }
sub CheckDeployed { #chomp (my $id = $_); my $id = shift; my $deployedcounter = 0; foreach (@deployeduid) { #chomp $_; if ( $id eq $_ ) { print "I found $id in the deployedfile with the timestamp of $de +ployedtimestamp[$deployedcounter]\n"; my $temptime = time; my $comparetime = ($temptime - 86400 * 3); if ($deployedtimestamp[$deployedcounter] < $comparetime) { my $oldtime = $deployedtimestamp[$deployedcounter]; chomp ($deployedtimestamp[$deployedcounter] = $temptime); print TEMPDEPLOYED "$id $deployedtimestamp[$deployedcounte +r] 2\n" or die $!; return "0"; } else { chomp $deployedtimestamp[$deployedcounter]; print TEMPDEPLOYED "$id $deployedtimestamp[$deployedcounte +r] 1\n" or die $!; return 1; } $deployedcounter++; } elsif ( $_ ne "" ) { #reserved } $deployedcounter++ } my $temptime = time; chomp ($deployedtimestamp[$deployedcounter] = $temptime); print TEMPDEPLOYED "$id $deployedtimestamp[$deployedcounter] 1\n +" or die $!; return "2"; }

Replies are listed 'Best First'.
Re^3: returns not working
by chromatic (Archbishop) on Aug 24, 2005 at 17:47 UTC

    Do you mean to loop over @deployedfile or @deployeduid?

    I also suspect your conditionals may be incorrect. Your indentation makes it very difficult to follow, though that could be an artifact of copying and pasting.

    Why are you chomping so often? It's an idempotent operation if you've already removed trailing input record separators, but if you clean the data where you have it, you can remove that code.