help-octave
[Top][All Lists]
Advanced

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

Perl-like regexp support ?


From: Pascal A. Dupuis
Subject: Perl-like regexp support ?
Date: Mon, 6 Dec 2004 04:37:46 -0600
User-agent: Mutt/1.5.6+20040722i

Hello,

I'm working on a project where data follows a very complicated path:
generated from a scope reading as text file, then processed under
octave to generate SQL commands, introduced in a database, then
re-read from the database, reworked, and so on.

Each step is performed by some specific octave portion, but sometimes
I need to alter directly the SQL file. At this stage I use Perl
because the regexp support is invaluable at coping with all the
potential problems. But this requires further octave<->perl steps.

I was wondering if would be possible to interface directly octave with
a perl-like regexp engine ? There is a regexp() function in MatLab7, I
would imagine a interface like:

function [status, ...] = regexp(target, regexp, switch)
where -target is the user-defined string
      -regexp is defined the perlish way
      -switch are the perl switches like g (global), i
      (case-insensitive), o (compile once) 
with one output argument, it would return a status (match/no match)
with more than one output argument, the first is a status (how many
subexpr matched), the second one is the first subexpr, and so on. So:

Perl way:
# search for the word 'values' in between two substrings. The first
# match is made non-greedy to find the first occurence
        if (/(.*?)(values)(.*)/gio) {
                ($order, $keyword, $data) = ($1, $2, $3);       
        }
octave way:
(status, order, keyword, data) = regexp(my_line, '(.*?)(values)(.*)',
'gio')

if (status > 0) ... endif

So, Perl $1 would become the second output arg, and so on.

According to Perl doc (perldoc perlembed), Perl has a C API and the
problem is to write the right interface between octave internals and
C.

I can help writing/debugging the stuff, anyone else interested ?

Pascal Dupuis

-- 
Dr. ir. Pascal Dupuis
K. U. Leuven, ESAT/ELECTA (formerly ELEN):  http://www.esat.kuleuven.ac.be/
Kasteelpark Arenberg, 10; B-3001 Leuven-Heverlee, Belgium
Tel. +32-16-32 10 21 -- Fax +32-16-32 19 85



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]