Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

howd oes regex work

Name: Anonymous 2008-10-20 0:19

???

Name: Anonymous 2008-10-24 12:39

btw, here's the code I tested them with. I didn't bother adapting all of the tests since this pretty much gets the point across anyway, but it shouldn't be hard to do.


#!/bin/sh

testperl() {
    perl -le "'$1' =~ /$2/ or print 'wrong result'"
}

testawk() {
    echo $1 | awk "/$2/ {m = 1} END {if (! m) print \"wrong result\"}"
}

testpython() {
    python -c "if not __import__('re').search(r'$2', '$1'): print 'wrong result'"
}

repeat() {
    r=$1
    e="$2"
    while [ $r -gt 0 ]; do
        r=`expr $r - 1`
        echo -n "$e"
    done
    echo
}

# adapt these as you like, but 25 is sufficently enough to show how bad perl sucks at this
for n in 1 5 10 20 25; do
    i=`repeat $n a`
    r=`repeat $n a\?`$i
    echo n = $n
    for body in awk perl python
    do
        echo "$body":
        time test$body $i $r
    done
    echo
done

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List