[33152] in Perl-Users-Digest
Perl-Users Digest, Issue: 4431 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 14 05:17:25 2015
Date: Thu, 14 May 2015 02:17:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 14 May 2015 Volume: 11 Number: 4431
Today's topics:
Re: interior arrows <ruben@mrbrklyn.com>
Re: rename key <rweikusat@mobileactivedefense.com>
Re: rename key <gravitalsun@hotmail.foo>
very slow regex <gravitalsun@hotmail.foo>
Re: very slow regex <peter@makholm.net>
Re: very slow regex <bauhaus@futureapps.invalid>
Re: very slow regex <justin.1503@purestblue.com>
Re: very slow regex <rweikusat@mobileactivedefense.com>
Re: very slow regex <peter@makholm.net>
Re: very slow regex <derykus@gmail.com>
Re: very slow regex <gravitalsun@hotmail.foo>
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. <gravitalsun@hotmail.foo>
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. deangwilliam30@gmail.com
Re: wordx....not_wordx...wordy pattern matching. <justin.1503@purestblue.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 May 2015 22:27:34 -0400
From: ruben safir <ruben@mrbrklyn.com>
Subject: Re: interior arrows
Message-Id: <mj116m$ijh$1@reader1.panix.com>
On 03/15/2015 05:32 PM, Rainer Weikusat wrote:
> Omitting arrows between bracketed subscripts is possibly not such a good
> idea as this may adversely affect legibility. Case in point:
>
> sub get_obj_at
> {
> return $_[0]->[IN_ORDER]->[$_[1]];
> }
>
> versus
>
> sub get_obj_at
> {
> return $_[0][IN_ORDER][$_[1]];
> }
the second one is clearer.
------------------------------
Date: Wed, 13 May 2015 13:18:21 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: rename key
Message-Id: <87k2wc8ycy.fsf@doppelsaurus.mobileactivedefense.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> is there any internal hack to rename a hash key (without ref to it) ?
It's not possible to change the 'name' of a hash key as this name is the
key.
Ultra-condensed, simplified description: A 'hash table' is an array
of linked lists. An arithemtic transformation is performed on the key to
turn it to an index into this array and both value and key are then put
onto this list. On lookup, the same transformation is performed
on the key whose value (if any) is supposed to be determined and
the list found in this way is then searched for a matching key.
It's possible to re-associated the SV (scalar) associated with a certain
hash key with a different key using the perl C api, eg, this xs function
-------------
/* includes */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = hash_move
SV *
hash_move(hv, to, from)
HV *hv
SV *to
SV *from
PROTOTYPE: \%$$
PREINIT:
SV *v, **rc;
char *t_key, *f_key;
STRLEN t_key_len, f_key_len;
CODE:
f_key = SvPV(from, f_key_len);
rc = hv_fetch(hv, f_key, f_key_len, 0);
if (!rc) XSRETURN_YES;
v = *rc;
t_key = SvPV(to, t_key_len);
rc = hv_store(hv, t_key, t_key_len, v, 0);
if (!rc) XSRETURN_UNDEF;
SvREFCNT_inc(v);
hv_delete(hv, f_key, f_key_len, 0);
XSRETURN_YES;
-------------
will do the trick. The reference count of the v SV has to be incremented
because (for some idiotic reason) hv_delete mortalizes the SV it returns
to the caller (starting with perl 5.14, this is at least documented
...).
Example Perl program
-------
use Devel::Peek;
use MAD::xso_loader '/tmp/hm.xso';
sub hash_move(\%$$);
$h{a} = 'b';
Dump($h{a});
hash_move(%h, 'b', 'a');
Dump($h{b});
-------
I realize this is less-than-useful but my so-called employer has some
claim to the infrastructure code used for compiling and linking
standalone .xs files and to the loader. Since the 'compile and link'
scripts are IMHO trivial, I posted them a while ago and the same posting
also contains a description how to load a shared object into perl via
DynaLoader.
Considering that linking C code into perl is not useful wrt 'getting
your name published on the WWW', this is something where CPAN will
let you squarely down (Inline:C might be usuable but that's a PITA and I
wouldn't ever want to use it myself).
------------------------------
Date: Wed, 13 May 2015 17:27:00 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: rename key
Message-Id: <mivmul$5jh$1@news.grnet.gr>
On 13/5/2015 15:18, Rainer Weikusat wrote:
> -------------
> /* includes */
> #include "EXTERN.h"
> #include "perl.h"
> #include "XSUB.h"
>
> MODULE = hash_move
>
> SV *
> hash_move(hv, to, from)
> HV *hv
> SV *to
> SV *from
> PROTOTYPE: \%$$
> PREINIT:
> SV *v, **rc;
> char *t_key, *f_key;
> STRLEN t_key_len, f_key_len;
> CODE:
> f_key = SvPV(from, f_key_len);
> rc = hv_fetch(hv, f_key, f_key_len, 0);
> if (!rc) XSRETURN_YES;
> v = *rc;
>
> t_key = SvPV(to, t_key_len);
> rc = hv_store(hv, t_key, t_key_len, v, 0);
> if (!rc) XSRETURN_UNDEF;
>
> SvREFCNT_inc(v);
> hv_delete(hv, f_key, f_key_len, 0);
> XSRETURN_YES;
> -------------
>
> will do the trick. The reference count of the v SV has to be incremented
> because (for some idiotic reason) hv_delete mortalizes the SV it returns
> to the caller (starting with perl 5.14, this is at least documented
> ...).
this is very interesting .
------------------------------
Date: Wed, 13 May 2015 14:03:07 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: very slow regex
Message-Id: <mivb0c$olh$1@news.grnet.gr>
'~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
/(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
any idea ?
In fact the problem is bigger than the posted regex
------------------------------
Date: Wed, 13 May 2015 13:59:46 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: very slow regex
Message-Id: <87h9rg1ydp.fsf@vps1.hacking.dk>
George Mpouras <gravitalsun@hotmail.foo> writes:
> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>
> any idea ?
Use the whole language and not just regexpes:
my @F = split /~~/, '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I';
$F[-1] =~ /^\d*\s*$/;
Or a bit more terse
(split /~~/, '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I')[-1] =~ /^\d*\s$/;
//Makholm
------------------------------
Date: Wed, 13 May 2015 14:09:36 +0200
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: very slow regex
Message-Id: <mivert$enm$1@dont-email.me>
On 13.05.15 13:03, George Mpouras wrote:
> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>
>
>
>
>
>
> any idea ?
I'd speculate about catastrophic backtracking.
(Guesses: starting somewhere after the third 1~, possibly
exacerbated by lack of an early anchor, no fences, and
starred ones near the end that match only when empty.)
------------------------------
Date: Wed, 13 May 2015 12:44:17 +0100
From: Justin C <justin.1503@purestblue.com>
Subject: Re: very slow regex
Message-Id: <h1qb2c-725.ln1@eddie.masonsmusic.co.uk>
On 2015-05-13, George Mpouras <gravitalsun@hotmail.foo> wrote:
> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>
> any idea ?
> In fact the problem is bigger than the posted regex
my @things = split /~~/, '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I';
Justin.
--
Justin C, by the sea.
------------------------------
Date: Wed, 13 May 2015 13:21:53 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: very slow regex
Message-Id: <87fv708y72.fsf@doppelsaurus.mobileactivedefense.com>
"G.B." <bauhaus@futureapps.invalid> writes:
> On 13.05.15 13:03, George Mpouras wrote:
>> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
>> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>>
>>
>>
>>
>>
>>
>> any idea ?
>
> I'd speculate about catastrophic backtracking.
Obviously. The minimum number of characters including ~ each of the .*?
can match while still allowing the match to succeed can only be
determined by an exhaustive search. Considering that there are 23 (.*?),
this will take 'some time'.
------------------------------
Date: Wed, 13 May 2015 15:35:16 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: very slow regex
Message-Id: <87d2241tyj.fsf@vps1.hacking.dk>
George Mpouras <gravitalsun@hotmail.foo> writes:
> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>
> any idea ?
I think that splitting on '~~' is the best way forward, but the
alternative is to rephrase (.*?) slightly so it stops scanning as soon
as it hits '~~'.
If you know that the content of the fields can never contain '~' the
obvious way would to just use ([^~]*).
Otherwise I would guess that you could use something like
(?:(?!~~).)*
This matches any character that is not the first character in a '~~'
sequence. If you have a '1~~~2' sequence this would make the second field
start with '~' instead of have the first field end with '~'. That
ambiguity can't really be solved with the information at hand.
> In fact the problem is bigger than the posted regex
So do what you would do with any code that gets too complex. Refactor it
into smaller bits the solved tiny well-defined parts of the problem. In
your case that could be to split the sting into fileds and then validate
the individual fields.
//Makholm
------------------------------
Date: Wed, 13 May 2015 13:11:54 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: very slow regex
Message-Id: <d7eb4d2b-af48-4fe8-a49c-9cd63d182850@googlegroups.com>
On Wednesday, May 13, 2015 at 4:02:41 AM UTC-7, George Mpouras wrote:
> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>
>
>
>
>
> any idea ?
> In fact the problem is bigger than the posted regex
You could save sore eyes with an /x and a repeat count, eg,
/(?: (.*?)~~){12} ) (\d*) \s* $/x
One cautionary note about the suggested split() approach is that it won't necessarily be a drop-in for the regex.
A split() would need a field count for instance:
@F =split(/~~/,....); @F => 13 or say "no match"
--
Charles DeRykus
------------------------------
Date: Thu, 14 May 2015 01:37:43 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: very slow regex
Message-Id: <mj0jnr$j7k$1@news.grnet.gr>
On 13/5/2015 23:11, C.DeRykus wrote:
> On Wednesday, May 13, 2015 at 4:02:41 AM UTC-7, George Mpouras wrote:
>> '~~1~~~~~~0~~foo~~1~~0~~~~0~~0~~~~1~~~~~~~~~~~~~~~~4~~I' =~
>> /(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(.*?)~~(\d*)\s*$/;
>>
>>
>>
>>
>>
>> any idea ?
>> In fact the problem is bigger than the posted regex
>
>
> You could save sore eyes with an /x and a repeat count, eg,
>
> /(?: (.*?)~~){12} ) (\d*) \s* $/x
>
>
> One cautionary note about the suggested split() approach is that it won't necessarily be a drop-in for the regex.
>
> A split() would need a field count for instance:
>
> @F =split(/~~/,....); @F => 13 or say "no match"
>
Can not use split
?: the parentheses are needed
(.*?)~~){12} I can not doit because the external commersial application
(nonames) can not understand it.
I found workaround, I post it because I found it a litle unexpected
------------------------------
Date: Wed, 13 May 2015 13:04:24 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <7c4511bd-908c-4cb4-b0e4-f880bc5390de@googlegroups.com>
As previously stated thank you very much for responding.
I tried all of the above on my .pas file but they don't seemed to give me the pairings unless I'm doing something wrong.
I've provided the main loop of my powerbasic code and what it does at the top along with my test of your code.
I can do this in Powerbasic but have a feeling that it could be done a lot easier in Perl. Thanks for bearing with me and sorry if I'm making a bit of a meal re explaining what I'm looking for.
Best Regards Dean
#perl "$(FULL_CURRENT_PATH)"
#Rainer Weikusat
local $/ = undef;
open FILE, "c:/uMain.pas" or die "Couldn't open file: $!";
binmode FILE;
my $str = <FILE>;
close FILE;
#this works
#print $str
use feature 'say';
while ( $str =~ /(proc(.*?)begin)/g ) {
my($match, $between, $start ) = ( $1, $2, $-[0] );
if ( $between =~ /proc/g) {
pos($str) = $start + pos($between);
say "failed at $start";
next;
}
say "ok at $start";
}
# String found where operator expected at test1.pl line 16, near "say "failed at
# start""
# (Do you need to predeclare say?)
# String found where operator expected at test1.pl line 19, near "say "ok at $sta
# t""
# (Do you need to predeclare say?)
# "use" not allowed in expression at test1.pl line 10, at end of line
# syntax error at test1.pl line 10, near "$str
# use feature "
# syntax error at test1.pl line 16, near "say "failed at $start""
# syntax error at test1.pl line 19, near "say "ok at $start""
# Execution of test1.pl aborted due to compilation errors.
#my $str = 'proc1_abc_proc2_edf_begin_ghi_begin_en';
#$str =~ /^.*(proc.*?begin)/ and print($1, "\n");
sub add_traces
{
my ($proc, $begin, $trace);
pos($_[0]) = $_[1];
while ($_[0] =~ /(proc.*?(?=_)|begin)/g) {
if (substr($1, 0, 4) eq 'proc') {
$trace = "[trace_$1]";
$begin = add_traces($_[0], pos($_[0]));
substr($_[0], $begin, 0, $trace);
pos($_[0]) = $begin + length($trace);
next;
}
return pos($_[0]);
}
}
add_traces($str);
print("$str\n");
#seems to print the whole file out unchanged
#I'm trying to find the closest procedure/function/begin pairing so that I can extract the proc name and
#insert a line immediately after begin to trace the procedure function.
# procedure lstEpics_update(f:TfMain);
# var
# i:Integer;
# begins_with:string;
# sl:TStringList;
# begin
# gTrc.log('trace... lstEpics_update');
# #Here's what I'm having to do in powerbasic
# FUNCTION PBMAIN () AS LONG
# DIM lns$(0)
# DIM aProc_nm$(0)
# DIM aProc_pos&(0)
# DIM aBegin_pos&(0)
# LINE INPUT "input project directory path", proj_dir$
# IF proj_dir$ = "" THEN
# proj_dir$ = "C:\14_10_09_d5\14_09_09_d5"
# ? "proj_dir$ is now ";proj_dir$ : WAITKEY$
# END IF
# fls$ = csv_of_pas_fls(proj_dir$)
# no_fls& = PARSECOUNT(fls$)
# FOR fl_x& = 1 TO no_fls&
# fl_nm$ = PARSE$(fls$,fl_x&)
# IF fl_nm$ = "StdTools.pas" THEN ITERATE
# IF fl_nm$ = "SqLite3Api.pas" THEN ITERATE
# gPth$ = proj_dir$ & "\" & fl_nm$
# fl$ = fl_to_str(gPth$)
# IF TALLY(fl$,"implementation") <>1 THEN STDOUT "too many implementations" :WAITKEY$:EXIT FUNCTION
# REGEXPR "(^implementation)" IN fl$ TO iPos&,iLen&
# implementation_pos& = iPos& + iLen&
# start& = implementation_pos&
# ctr& = 0
# REDIM aProc_nm$(1 TO 1000)
# REDIM aProc_pos&(1 TO 1000)
# DO
# REGEXPR "(^procedure)|(^function)[^;(]+" IN fl$ AT start& TO iPos& , iLen&
# IF iPos& THEN
# proc_ln$ = MID$(fl$,iPos&,iLen&)
# REGREPL "(^procedure)|(^function)" IN proc_ln$ WITH "" TO dummy&, proc_nm$
# IF (INSTR(proc_nm$, "FormCreate") = 0) AND (INSTR(proc_nm$, "TTrc") = 0) THEN 'the FormCreate functions call TTrc.log BEFORE it's object is created so don't write to them
# INCR ctr&
# aProc_nm$(ctr&) = proc_nm$ 'bug here...subscript out of range when...ctr& = 10 AND fl_nm$ = "SqLite3Api.pas"
# aProc_pos&(ctr&) = iPos&
# END IF
# ELSE
# EXIT DO
# END IF
# start& = iPos& + iLen&
# LOOP
# IF ctr& < 1 THEN ITERATE
# REDIM PRESERVE aProc_nm$(1 TO ctr&)
# REDIM PRESERVE aProc_pos&(1 TO ctr&)
# REDIM aBegin_pos&(1 TO ctr&) 'this is max size cos not every proc has a begin so use a ctr to fill
# begin_x& = 0
# FOR i& =1 TO ctr&
# proc_pos& = aProc_pos&(i&)
# REGEXPR "(^begin)" IN fl$ AT proc_pos& TO begin_pos& 'look for next begin after this proc_pos
# IF begin_pos& = 0 THEN EXIT FOR
# IF i& < ctr& AND begin_pos& > aProc_pos&(i&+1) THEN ITERATE
# INCR begin_x&
# aBegin_pos&(begin_x&) = begin_pos&
# NEXT
# IF begin_x& = 0 THEN ITERATE 'does this solve the begin_x& = 0 bug on the next line
# REDIM PRESERVE aBegin_pos&(1 TO begin_x&) 'bug here cos begin_x& is 0 and ctr& is only 1 for uFast_xml_pth_to_xml_indx.pas
# 'must do replacements backwards else you'll mess up positions in arrays.
# FOR i& = begin_x& TO 1 STEP -1 'likely that begin_X& < ctr& ie no of begins < no of "procs" so...match the right ones
# begin_pos& = aBegin_pos&(i&)
# first_bit$ = MID$(fl$,1 TO begin_pos& + 4)
# matching_proc_x& = get_matching_proc_x( begin_pos&, aProc_pos&() )
# this_proc_nm$ = aProc_nm$(matching_proc_x&)
# mid_bit$ = $CRLF & "gTrc.log(" & $SQ & "trace..." & this_proc_nm$ & $SQ & ");" 'need trace... to distinguish these logs so you can comment them all in/out
# last_bit$ = MID$(fl$,begin_pos& + 5 TO LEN(fl$))
# fl$ = first_bit$ & mid_bit$ & last_bit$
# NEXT
# STDOUT fl$
# EXIT FOR 'just for debugging
# NEXT
# ? "done"
# WAITKEY$
# END FUNCTION
------------------------------
Date: Wed, 13 May 2015 13:14:21 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <93ed6d6e-e248-4f48-a530-347c717ec95d@googlegroups.com>
here's a skeleton of the data file that get's slurped into the string.
procedure blob0 a stray proc line
procedure blob1 closest proc preceding first begin
var
somevar...
begin
<insert trace line here
begin
end;
end;
function blob2 closest function line preceding first begin
var
some var
begin
<insert trace line here
begin
end;
end;
From the above I'd be looking to get...
procedure blob1 closest proc preceding first begin
var
somevar...
begin
and replace it with....
procedure blob1 closest proc preceding first begin
var
somevar...
begin
gTrc.log('blob1')
and the same for
function blob2 closest function line preceding first begin
var
some var
begin
ie appending the line...gTrc.log('blob2') to the end
to start with though I just need the substrings
procedure blob1 closest proc preceding first begin
var
somevar...
begin
and
function blob2 closest function line preceding first begin
var
some var
begin
I hope this makes things a bit clearer.
------------------------------
Date: Wed, 13 May 2015 13:15:46 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <180c1e7b-24f0-4a76-a8f4-d816cfdc1c28@googlegroups.com>
This is my first foray into Perl and having played with some of the one liner's...it looks very powerful
------------------------------
Date: Wed, 13 May 2015 13:35:27 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <9cd1eec3-cb99-4d9a-8fcd-c6d3047baaae@googlegroups.com>
The pseudocode is this...
make sure there's only one word at the start of a line called "implementation" and ignore everything before it.
keep track of each "procedure" and "function" at the start of a line until you find a "begin" at the start of a line and when you do...the last "procedure" or "function" upto the end of the "begin" line is a "block of interest".
Once you've found this ignore all subsequent begins until you see another "procedure" or "function" at the start of a line and repeat the process i.e. matching the last procedure/function you've tracked with the first begin.
Again I hope this helps.
------------------------------
Date: Thu, 14 May 2015 10:05:06 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <mj1he3$scr$1@news.grnet.gr>
On 13/5/2015 23:35, deangwilliam30@gmail.com wrote:
> The pseudocode is this...
> make sure there's only one word at the start of a line called "implementation" and ignore everything before it.
> keep track of each "procedure" and "function" at the start of a line until you find a "begin" at the start of a line and when you do...the last "procedure" or "function" upto the end of the "begin" line is a "block of interest".
> Once you've found this ignore all subsequent begins until you see another "procedure" or "function" at the start of a line and repeat the process i.e. matching the last procedure/function you've tracked with the first begin.
> Again I hope this helps.
>
too many senseless emails ...
just write three lines of sample lines and what do you want as result
------------------------------
Date: Thu, 14 May 2015 00:20:15 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <7c71bc36-41f9-4dcf-b846-333b3d49ab95@googlegroups.com>
The skeleton above and the pseudocode seem pretty clear to me.
Three lines wouldn't explain that.
Thanks for your input though.
------------------------------
Date: Thu, 14 May 2015 00:24:47 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <ce2df7ad-99af-4cda-9788-efb2cb1aea18@googlegroups.com>
btw asking for "lines" of "lines" is senseless. There's no such thing.
------------------------------
Date: Thu, 14 May 2015 00:41:19 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <cad4ad47-d5e6-4b6b-bb63-c1b64dcc4ecf@googlegroups.com>
In compliance with George's request. Here are two examples of the text blocks I want to extract.
procedure blob1 closest proc preceding first begin
var
somevar...
begin
The above is 4 lines not 3 but sometimes the text blocks I want will only be 2 lines long e.g.
procedure blob3;
begin
I want all of these "procedure/function...begin" text blocks in the program ignoring other stray "procedure", "function" and "begin" substrings.
I have provided the pseudocode above but if someone has a better idea...please feel free.
------------------------------
Date: Thu, 14 May 2015 00:50:40 -0700 (PDT)
From: deangwilliam30@gmail.com
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <1fce0af2-1b28-48fe-9f92-8b81e1592119@googlegroups.com>
To re-iterate...all we can rely on is that there are the words "procedure", "function" and "begin" at the start of some of the lines albeit possibly preceded by <space> or <tab> and the substrings to be extracted are...
the last "procedure" (before a "beging") to "begin" and
the last "function" (before a "beging") to "begin"
------------------------------
Date: Thu, 14 May 2015 09:56:01 +0100
From: Justin C <justin.1503@purestblue.com>
Subject: Re: wordx....not_wordx...wordy pattern matching.
Message-Id: <1i4e2c-fn1.ln1@eddie.masonsmusic.co.uk>
On 2015-05-14, deangwilliam30@gmail.com <deangwilliam30@gmail.com> wrote:
> The skeleton above and the pseudocode seem pretty clear to me.
> Three lines wouldn't explain that.
> Thanks for your input though.
Fercryinoutloud, I don't know what/where you think you're replying but
this is usenet, there are conventions that should be adhered to if you
expect people to help. If you persistently, blatantly flout convention
you will alienate many of the people best able to help you.
Please, always quote the post you're replying to to provide conect to
people reading your post.
Also, this might be helpful:
http://en.wikipedia.org/wiki/Posting_style#Quoting_previous_messages
Justin.
--
Justin C, by the sea.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4431
***************************************