in reply to Re: Capturing substrings with complex delimiter, up to a maximum
in thread Capturing substrings with complex delimiter, up to a maximum
Thanks for your rapid response. I tried to adapt your suggestion to a subroutine which I could easily drop into my test file. I found that at first it did not pass all tests.
Results:sub _browseruk_recognize_limited_urls { my ($input, $max) = @_; my @captures = $input =~ m[(https?://.+?)(?:,(?=http)|$)]g; return [ @captures[ 0 .. $max-1 ] ]; }
capture.t .. not ok 1 - 1 URL # Failed test '1 URL' # at capture.t line 18. not ok 2 - 2 URLs (one containing a comma) ok 3 - 3 URLs (one containing a comma) ok 4 - Still only 3 URLs (one containing a comma); reject those over m +ax 1..4 # Structures begin differing at: # $got->[1] = undef # $expected->[1] = Does not exist # Failed test '2 URLs (one containing a comma)' # at capture.t line 23. # Structures begin differing at: # $got->[2] = undef # $expected->[2] = Does not exist # Looks like you failed 2 tests of 4. Dubious, test returned 2 (wstat 512, 0x200) Failed 2/4 subtests Test Summary Report ------------------- capture.t (Wstat: 512 Tests: 4 Failed: 2) Failed tests: 1-2 Non-zero exit status: 2 Files=1, Tests=4, 1 wallclock secs ( 0.13 usr 0.04 sys + 0.11 cusr + 0.05 csys = 0.33 CPU) Result: FAIL shell returned 1
However, when I grepped for definedness ...
... all tests passed.sub _browseruk_recognize_limited_urls { my ($input, $max) = @_; my @captures = $input =~ m[(https?://.+?)(?:,(?=http)|$)]g; return [ grep { defined($_) } @captures[ 0 .. $max-1 ] ]; }
Thank you very much.
Jim Keenan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Capturing substrings with complex delimiter, up to a maximum
by BrowserUk (Patriarch) on Oct 30, 2013 at 01:53 UTC |