A few comments to your code. I downloaded it and got it run with these mods:
sub splitAB { my $STRING = shift; my $PATTERN = shift; # when debugging "print is your friend" print "pattern in sub splitAB= $PATTERN\n"; ##### print "string in sub splitAB = $STRING\n"; ##### my @OUTPUT = split(/\Q$PATTERN\E/, $STRING, 2); ##### $a = $b = ''; if (@OUTPUT > 0) { $a = $OUTPUT[0]; } if (@OUTPUT > 1) { $b = $OUTPUT[1]; } } sub decodeURLstr { my $S = shift; return unescape( join(' ', split('\+', $S) ) ); ##### }
In splitAB, the "?" has meaning to the regex engine, the \Q and \E tells split not to pay attention to that. output with my modifications:
pattern in sub splitAB= ? string in sub splitAB = file:///c:/html/testing.html?P1=123&P2=%28%28B +LAH+BLAH+BLAH%29%29 pattern in sub splitAB= # string in sub splitAB = P1=123&P2=%28%28BLAH+BLAH+BLAH%29%29 R: P1 R: 123 R: P2 R: ((BLAH BLAH BLAH)) Process completed successfully
I guess that is what you wanted?
From looking at the code and the use of substr(), I am guessing that you have a C background? In Perl, the use of regex instead of substr is the norm. As you write more Perl, you will use regex more often. In addition, you will start using modules for common task like parsing a URI. You "rolled your own" without necessity. I can tell that a lot of work went into your code. But you made the job harder on yourself than need be. Pay attention to haukex's post.

Have a happy and safe 4th of July!

Update: Do not use $a or $b. These variables have special meaning to Perl in sort. Use of them will cause problems in code that sorts.

Update 2: perhaps

my @OUTPUT = split(/\Q$PATTERN\E/, $STRING, 2); ##### $a = $b = ''; if (@OUTPUT > 0) { $a = $OUTPUT[0]; } if (@OUTPUT > 1) { $b = $OUTPUT[1]; }
better written? as (comments about use of $a,$b not withstanding):
($a, $b) = split(/\Q$PATTERN\E/, $STRING, 2); ##### $a //= ''; #null string if undefined $b //= ''; #null string if undefined

In reply to Re: RegExp error PLEASE HELP! by Marshall
in thread RegExp error PLEASE HELP! by harangzsolt33

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.