Here is the problem:
I am decrypting a file. I am using a module/script that was not written by me nor is the original author redilay available for assistance. At one point there is a matching operation that fails for one file, but passes for another, but the only thing that chagnes is the filename. The status messages from GnuPG are identical, the file contents are identical... only the extension of the file changes.

For your review, the sections of code that are in question, in the order in which they are encountered:
Section 1

my $new_filename = $full_filename; $new_filename =~ s/(\.gpg)|(\.encrypted)/\.decrypted/;

Section 2
$error ||= "Unexpected signer '$signer' is not '$expected_sender'." unless ($signer =~ m/\Q$expected_sender\E/);

The file that results in the m// making setting an error is when I use a file named 'FILE.gpg' or 'FILE.encrypted'. If I decrypt a file named 'FILE.pgp' the m// in section 2 does not create an error.

I ran the script and printed out the contents of the variables before the m// is executed and regardless of file name (assuming the contents are identical) it is something similar to the following (I will change the key info since this is private material):
$signer = 'GOODSIG 86125876138571635 ClientKey'
$expected_signer = '';

Thus the following command is evaluated regardless of filename:

$error ||= "Unexpected signer 'GOODSIG 86125876138571635 ClientKey' is + not ''." unless ('GOODSIG 86125876138571635 ClientKey' =~ m/\Q\E/);
yet sometimes an error is created, sometimes not.

My only thoughts is that when I pass a file name that results in a match in Section 1 something is set internally in perl that causes the match in Section 2 to set the error, but this is deductive reasoning, not solid knowledge of perl. And that is what I am hoping to gain - an understanding of how perl works so I can solve this problem.

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


In reply to Regular Expression gotchas ? by the_Don

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.