I've got a subroutine that I'm trying to use return's in. At first I tried returning a value with return(0); or return(1); which did not seem to work. For the most part, if I just use return; it does work EXCEPT as noted in the code below. What am I not understanding about returns or What did I mess up? *note only one value is passed to the subroutine, a userid.*
sub CheckDeployed { chomp (my $id = $_); 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; # Set comparetime to current time - 4 days 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; ### Jumps back to if ( $id eq $_ ) not sure why. } else { chomp $deployedtimestamp[$deployedcounter]; print TEMPDEPLOYED "$id $deployedtimestamp[$deployedcounter] 1 +\n" or die $!; return; } $deployedcounter++; } elsif ( $_ ne "" ) { #reserved for possible processing } $deployedcounter++ } my $temptime = time; chomp ($deployedtimestamp[$deployedcounter] = $temptime); print TEMPDEPLOYED "$id $deployedtimestamp[$deployedcounter] 1\n +" or die $!; return; }

In reply to returns not working by Markn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.