pattern matching dynamic strings w/ regex ending in $ problem

Discussion in 'Perl Misc' started by rader, May 2, 2005.

  1. rader

    rader Guest

    I'm seeing a simple, ah, problem with perl 5.8.0...

    chive(rader): perl -v | head -2 | tail -1
    This is perl, v5.8.0 built for i386-linux-thread-multi

    chive(rader): cat crud
    #!/usr/bin/perl
    $a = 'fuBar';
    $b = 'Bar$';
    $a_new = `echo -n $a`;
    $b_new = `echo -n $b`;
    if ( $a_new =~ /$b_new/ ) {
    print "match\n";
    } else {
    print "no match?!\n";
    }

    chive(rader): ./crud
    no match?!

    Anybody know of a workaround? The code above behaves as expected
    with 5.6.x. Could this actually be a bug?

    steve
    - - -
    systems & network manager
    high energy physics
    university of wisconsin
    rader, May 2, 2005
    #1
    1. Advertising

  2. On 2005-05-02, rader scribbled these
    curious markings:

    [Posting to both clpmod and clpmisc is largely superfluous. Following up
    to and F'ups set to clpmisc.]

    > chive(rader): cat crud
    > #!/usr/bin/perl
    > $a = 'fuBar';
    > $b = 'Bar$';
    > $a_new = `echo -n $a`;
    > $b_new = `echo -n $b`;
    > if ( $a_new =~ /$b_new/ ) {
    > print "match\n";
    > } else {
    > print "no match?!\n";
    > }
    >
    > chive(rader): ./crud
    > no match?!


    Make sure that the results of the echo commands are actually what you
    expect. FWIW, it WFM on 5.8.6 i386-freebsd-thread-multi-64int.

    Best Regards,
    Christopher Nehren
    --
    I abhor a system designed for the "user", if that word is a coded
    pejorative meaning "stupid and unsophisticated". -- Ken Thompson
    If you ask the wrong questions, you get answers like "42" and "God".
    Unix is user friendly. However, it isn't idiot friendly.
    Christopher Nehren, May 3, 2005
    #2
    1. Advertising

  3. rader

    Paul Arthur Guest

    rader <> wrote:

    >I'm seeing a simple, ah, problem with perl 5.8.0...
    >
    >chive(rader): perl -v | head -2 | tail -1
    >This is perl, v5.8.0 built for i386-linux-thread-multi


    [paul@linux ~]$ perl -v

    This is perl, v5.8.5 built for i386-linux-thread-multi

    [paul@linux ~]$ cat rader.pl
    #!/usr/bin/perl

    use strict;
    use warnings;

    my $a = 'fuBar';
    my $b = 'Bar$';
    my $a_new = `echo -n $a`;
    my $b_new = `echo -n $b`;
    if ( $a_new =~ /$b_new/ ) {
    print "match\n";
    } else {
    print "no match?!\n";
    }
    >
    >chive(rader): ./crud
    >no match?!


    [paul@linux ~]$ ./crud.pl
    match

    >Anybody know of a workaround? The code above behaves as expected
    >with 5.6.x. Could this actually be a bug?


    If it is a bug, it's been fixed.
    Paul Arthur, May 3, 2005
    #3
  4. rader

    Ed Guest

    Paul Arthur wrote:

    > rader <> wrote:


    >>I'm seeing a simple, ah, problem with perl 5.8.0...
    >>Anybody know of a workaround? The code above behaves as expected
    >>with 5.6.x. Could this actually be a bug?


    > If it is a bug, it's been fixed.


    (Paul had used 5.8.5, where the problem did not appear.)

    I did some further poking at the problem with 5.8.0 (below). From what
    I see there, there may still be a bug with 5.8.5. I'm not that familiar
    with perl's UTF-8 handling, so bear with me if I misstate something
    here... The regex debug information indicates that UTF-8 came into play
    (for the problem case). I believe UTF-8 was enabled by default for
    5.8.0 and backed out with 5.8.1. So 5.8.5 may have the bug, but it
    could be masked since UTF-8 isn't enabled.

    Ed


    $ cat crud
    #!/usr/local/bin/perl
    use strict;
    use warnings;

    use re 'debug';

    my $a = 'fuBar'; my $a_new = qx(echo -n $a);
    my $b = 'Bar$';

    if ( $a eq $a_new ) {
    print "===> \$a eq \$a_new is true\n";
    }

    print "===> (\$a vs. \$b ) $a =~ /$b/ ...\n";
    if ( $a =~ /$b/ ) {
    print "===> match\n";
    } else {
    print "===> no match?!\n";
    }

    print "===> (\$a_new vs. \$b ) $a_new =~ /$b/ ...\n";
    if ( $a_new =~ /$b/ ) {
    print "===> match\n";
    } else {
    print "===> no match?!\n";
    }

    print "===> (\$a_new vs. Bar\$) $a_new =~ /Bar\$/ ...\n";
    if ( $a_new =~ /Bar$/ ) {
    print "===> match\n";
    } else {
    print "===> no match?!\n";
    }
    $ ./crud
    Compiling REx `Bar$'
    size 4 Got 36 bytes for offset annotations.
    first at 1
    rarest char B at 0
    1: EXACT <Bar>(3)
    3: EOL(4)
    4: END(0)
    anchored `Bar'$ at 0 (checking anchored isall) minlen 3
    Offsets: [4]
    1[3] 0[0] 4[1] 5[0]
    Omitting $` $& $' support.

    EXECUTING...

    ===> $a eq $a_new is true
    ===> ($a vs. $b ) fuBar =~ /Bar$/ ...
    Compiling REx `Bar$'
    size 4 Got 36 bytes for offset annotations.
    first at 1
    rarest char B at 0
    1: EXACT <Bar>(3)
    3: EOL(4)
    4: END(0)
    anchored `Bar'$ at 0 (checking anchored isall) minlen 3
    Offsets: [4]
    1[3] 0[0] 4[1] 5[0]
    Guessing start of match, REx `Bar$' against `fuBar'...
    Found anchored substr `Bar'$ at offset 2...
    Starting position does not contradict /^/m...
    Guessed: match at offset 2
    ===> match
    ===> ($a_new vs. $b ) fuBar =~ /Bar$/ ...
    Compiling REx `Bar$'
    size 4 Got 36 bytes for offset annotations.
    first at 1
    rarest char B at 0
    1: EXACT <Bar>(3)
    3: EOL(4)
    4: END(0)
    anchored utf8 `Bar'$ at 0 (checking anchored isall) minlen 3
    Offsets: [4]
    1[3] 0[0] 4[1] 5[0]
    UTF-8 regex...
    UTF-8 target...
    Guessing start of match, REx `Bar$' against `fuBar'...
    Did not find anchored substr `Bar'$...
    Match rejected by optimizer
    ===> no match?!
    ===> ($a_new vs. Bar$) fuBar =~ /Bar$/ ...
    Matching REx `Bar$' against `fuBar'
    Setting an EVAL scope, savestack=9
    2 <fu> <Bar> | 1: EXACT <Bar>
    5 <fuBar> <> | 3: EOL
    5 <fuBar> <> | 4: END
    Match successful!
    ===> match
    Freeing REx: `"Bar$"'
    Freeing REx: `Bar$'
    Freeing REx: `"Bar$"'
    $
    Ed, May 3, 2005
    #4
  5. Ernest Lergon, May 7, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee
    Replies:
    1
    Views:
    931
    Ilias Lazaridis
    Sep 22, 2006
  2. Xah Lee
    Replies:
    8
    Views:
    458
    Ilias Lazaridis
    Sep 26, 2006
  3. anonym
    Replies:
    1
    Views:
    1,003
    Knute Johnson
    Jan 15, 2009
  4. Xah Lee
    Replies:
    2
    Views:
    213
    Xah Lee
    Sep 25, 2006
  5. Replies:
    2
    Views:
    384
Loading...

Share This Page