isotope has asked for the wisdom of the Perl Monks concerning the following question:
Test 2 fails; grep has returned the whole input array:#!/usr/bin/perl -w use strict; use Test::More tests => 3; use Test::Differences; my @input = qw(nope skip uh-uh no yes stop yup not-me groovy wrong ok +ay); my @output = qw(yes yup groovy okay); my $re = qr/y/; eq_or_diff( [ grep( /y/, @input ) ], \@output, "Embedded RE" ); eq_or_diff( [ grep( $re, @input ) ], \@output, "Compiled, passed RE" + ); eq_or_diff( [ grep( /$re/, @input ) ], \@output, "Compiled, but slashe +d RE" );
grep_re....1..3
ok 1 - Embedded RE
not ok 2 - Compiled, passed RE
# Failed test (grep_re.t at line 13)
# +----+--------+----+----------+
# | Elt|Got | Elt|Expected |
# +----+--------+----+----------+
# * 0|nope * | |
# * 1|skip * | |
# * 2|uh-uh * | |
# * 3|no * | |
# | 4|yes | 0|yes |
# * 5|stop * | |
# | 6|yup | 1|yup |
# * 7|not-me * | |
# | 8|groovy | 2|groovy |
# * 9|wrong * | |
# | 10|okay | 3|okay |
# +----+--------+----+----------+
ok 3 - Compiled, but slashed RE
# Looks like you failed 1 tests of 3.
dubious
Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 2
Failed 1/3 tests, 66.67% okay
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
grep_re.t 1 256 3 1 33.33% 2
Failed 1/1 test scripts, 0.00% okay. 1/3 subtests failed, 66.67% okay.
Has anyone else experienced this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grep bug -- doesn't handle passed, precompiled regular expressions properly
by Roy Johnson (Monsignor) on Nov 30, 2005 at 21:02 UTC | |
|
Re: Grep bug -- doesn't handle passed, precompiled regular expressions properly
by Fletch (Bishop) on Nov 30, 2005 at 21:02 UTC | |
|
Re: Grep matches all elements if compiled regex is passed as EXPR
by ikegami (Patriarch) on Nov 30, 2005 at 21:07 UTC | |
|
Re: Grep matches all elements if compiled regex is passed as EXPR
by GrandFather (Saint) on Nov 30, 2005 at 21:11 UTC | |
|
Re: Grep matches all elements if compiled regex is passed as EXPR
by tphyahoo (Vicar) on Dec 02, 2005 at 13:36 UTC |