[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Importing search patterns



It would be a nice Macish use of MacPerl to be able import a search pattern
via MacPerl::Ask(), rather than type it directly into the script. However
there are difficulties importing the operators <i, g, o, e>. For instance:

        $str = MacPerl::Ask("What?", "/pattern/i");

returns '$str' as '/pattern/i' but a line such as: <if ($_ =~ $str) {}> is
clearly nonsense.

It is possible to take the pattern apart by:

        $str =~ /\/(.*)\/(.*)/;      #followed by:
        if ($_ =~ /$1/$2) {}

but MacPerl baulks at $2 since it expects an operator in that position.
That problem can be avoided by;

        if (eval('$_ =~ /$1/'.$2)) {print "Hooray\n"};

which seems to work, but the use of 'eval' for each line of the file slows
up execution and also mops up a relatively large amount of memory?

Apart from abandon the project has anybody any suggestions?

Alan