s{ ( [a-zA-Z]+ (?: ' [a-zA-Z]{1,2} )? ) }{ my $x = $1; $x =~ s/'s\z//; exists $dict{ lc( $x ) } ? $1 : "<@>$1"; }exg;

Okay, I understand that you have a basic s{}{} regex structure here, which means you're replacing something in the first {} group with the evaluated result of the second {} group. That's what the e modifier does. The g modifier means global replace, which means do each occurrence one by one. And the x modifier tells us to ignore spaces or comments within the regex.

The first part matches some word followed by (I'm not sure what (?: ' does and then I am not sure what )? does either. Does it mean match this group once or not at all?

Then you have another closing parentheses which is the end of the capture group. The second half of the regex s{}{} group contains Perl code that will be evaled when a match is found.

It looks like you have a regex within a regex. The embedded regex is also a replacement. It seems like you're removing something from the end of a word. I am not sure what the 's does. Or is this a literal letter "s" at the end of a word that makes the word possessive? That could be it. So, you are looking for a word in a dictionary.

The regex within the regex seems to make the problem. And even though you're not capturing anything with the embedded regex, the $1 still gets reset for some reason. Honestly, I don't understand the purpose of this whole code. I only understand that you're trying to replace some words with something else and you do a dictionary lookup. If the word is in the dictionary without the 's suffix (?), then you perform a replacement with that word, otherwise you put a <@> suffix in front of it, which I don't understand why. But since I don't understand what the input pattern might look like and what the desired output should look like, I cannot help. I just wrote this to show how I am trying to analyze your code, but I'm nowhere near this level of expert yet, so I cannot give you a solution. But it looks very complex code!


In reply to Re: Use of uninitialized value message? by harangzsolt33
in thread Use of uninitialized value message? by jwkrahn

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.