in reply to Regular Expression gotchas ?

The number one rule of learning by example is, Good Examples are Hard to Come By.

I would recommend (gently) that you learn perl first, via some other route, then try to fix this program, because it appears to me that its flaws are several and serious, particularly with regard to error checking.

I don't think it should ever let you get to that section 2 if $expected_signer is null; and clearly a regex match - at least, the one given - is inappropriate for determining the validity of the $signer.
I also think it should be bailing out (via die, for example) whenever an error is encountered, rather than setting an error message and continuing on with processing.
Also, if ".pgp" is a valid file suffix, it should make explicit allowance for it. Otherwise, it should throw an error for any invalid file suffix.

If my estimation of the situation is inaccurate, perhaps you could post more of the code, or provide a pointer to the program, if available.

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

Replies are listed 'Best First'.
Re: Re: Regular Expression gotchas ?
by the_Don (Scribe) on Feb 14, 2003 at 22:16 UTC

    I think that I have a pretty good understanding of basic perl and programming theories. What I don't understand is why what appears to be identical calls with identical data is resulting in two different outcomes.

    • True, I should add .pgp as a file that will result in a .decrypt extension... or just add .decrypt on the end regardless of what the original extension is.
    • The program dies at the end with one call to an email routine and messages if there was an error. Basically the same thing, and yes a little bit more processing, nothing too bad.
    • The program is checking with a regex against a list of signed keys that we have. The validity here lies in the PGP encryption system, not the power of Perl regex.
    • My possible intent was to have the null character imply that as long as a trusted, signed key was recognized as the signature then not to worry, but specifiying a particular sender in the perl would add some error checking in the system.

    What more do you want of the code? It will be hard for me to post the entire code since it is company material, but if you have a thought process about something going onn, I will surely put up pertinent pieces. In all there is at most 100 lines that are executed.

    the_Don
    ...making offers others can't rufuse.

      I think that I have a pretty good understanding of basic perl and programming theories.
      If you think 'FILE.gpg' and 'FILE.pgp' are "identical data", then I would have to dispute your claim.

      Furthermore, do you realize that m/\Q\E/ matches everything, and thus that
      $expected_sender = ''; if ( $signer =~ /\Q$expected_sender\E/ )
      will always be true?

      It is entirely unclear why/how your section 1 and section 2 could be related. Since you "know" that they are, you have useful information which you're not sharing. Do you want us to help, or not?

      jdporter
      The 6th Rule of Perl Club is -- There is no Rule #6.

        It appears that section 1 and section 2 are indeed related. Please see the replies below for an explanation.

        Many thanks to Hugo.

        the_Don
        ...making offers others can't rufuse.