in reply to returns not working

There are a couple of serious problems here.

chomp (my $id = $_);

$_ has nothing to do with the arguments to a subroutine. If you're actually passing in a value, use my $id = shift;. I don't know why you're chomping it here.

foreach (<@deployeduid>)

You don't need the angle brackets to iterate over a list. I suspect (but don't have time to confirm) that Perl treats this as a glob operation and doesn't give you the values that you expect. If that's the case, your conditional statements will be completely wrong and it may look like return is "not working".

Replies are listed 'Best First'.
Re^2: returns not working
by Markn (Initiate) on Aug 24, 2005 at 16:16 UTC
    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"; }

      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.