doc1623 has asked for the wisdom of the Perl Monks concerning the following question:

This will probably be a Homer S. Doh... but why doesn't this exit. It prints the Match... and the error mesg I have in a separate function then I see the ..passed print.. If tried exit as well. Thanks for any/all help
sub getsql{ my $dbh = shift; my $script = shift; my $insert= shift; local $/ = undef; open FILE, '<', $script, or die "Couldn't open SQL file"; my $insql = dwindex(<FILE>); my $outsql; if (length $insert) { $outsql = getinserts($insql,$insert); } else { print "in else:$insql\n"; if ($insql =~ m/.*~\w+~.*/) {print "MATCHED IT\n";} errmsg(1) && die if ($insql =~ m/.*~\w+~.*/); print "pased*********************\n"; $outsql = $insql; } close FILE; return $outsql; }

Replies are listed 'Best First'.
Re: no exit! (return)
by tye (Sage) on Aug 14, 2015 at 16:58 UTC

    Is errmsg() returning a false value?

    - tye        

      You were right! Sorry Couldn't see the forest through the trees. I had it printing a string..not returning one!
      MATCHED IT insert value/count mismatch: no insert value entered Died at db.pl line 51, <FILE> chunk 1
      Thanks everyone... DOH.....
      No...
      MATCHED IT insert value/count mismatch: no insert value entered pased*********************

        Please restructure your code as follows:

        if ($insql =~ m/.*~\w+~.*/) { print "MATCHED IT\n";} errmsg(1); die; };

        You don't show the code of errmsg, but most likely it really returns a false value and thus prevents the die from executing.

        If the left side of && is false, the right side will never be executed. Compare:

        This does not die...

        errstr() && die if (1); sub errstr { return 0; }

        This does:

        if (1){ errstr(); die; } sub errstr { return 0; }
Re: no exit!
by Laurent_R (Canon) on Aug 14, 2015 at 18:56 UTC
    Hmm, it is a bit difficult to answer your question when we don't know what the dwindex and getinserts subroutines do, and what the arguments ( the $dbh, $script and $insert parameters) are supposed to be.