in reply to SQL and Perl comparison

One of the problem is your use of % in Perl. In your SQL example, % is a wild card, but not in Perl though. The Perl version does not seem to be correct. Get rid of that % in the regexp.

SQL does a head-to-tail match (it matches the entire string) and that is why you need that % at the end. But Perl regexp does not work in that way, it can match a portion of the string.

For example, SQL 'like abc%' is close to Perl's '/^abc.*$/. But in your case, if DDD always appears at the beginning, there is no need to use ^ or $.

Your second regexp could be as simple as /DDD_t/, or /^DDD_t/.

For your last two regexp's, you can use substr() just like the SQL version does.

Replies are listed 'Best First'.
Re^2: SQL and Perl comparison
by dragonchild (Archbishop) on Oct 27, 2005 at 12:11 UTC
    In addition, '_' is the SQL equivalent of '.' in Perl regexes. So, 'DDD______%' is equivalent to 'DDD.{6}.*' in Perl. (Note that the two-character token ".*" is equivalent to '%' in SQL, not the one-character token '*'.)

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re^2: SQL and Perl comparison
by Win (Novice) on Oct 28, 2005 at 09:20 UTC
    There are problems with the SQL as well.