in reply to RegExp error PLEASE HELP!
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: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) ) ); ##### }
I guess that is what you wanted?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
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
better written? as (comments about use of $a,$b not withstanding):my @OUTPUT = split(/\Q$PATTERN\E/, $STRING, 2); ##### $a = $b = ''; if (@OUTPUT > 0) { $a = $OUTPUT[0]; } if (@OUTPUT > 1) { $b = $OUTPUT[1]; }
($a, $b) = split(/\Q$PATTERN\E/, $STRING, 2); ##### $a //= ''; #null string if undefined $b //= ''; #null string if undefined
|
|---|