advice on global

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

advice on global

Kevin-8
Hi,

I'm writing the function below to insert a line in a perl script.  The line
contains the line number that it's on.  I want to add a command to the
function that updates the previous calls to the function by means of a
global command, but getting nowhere with the syntax.  Something like:
g/debug/exe "line 4 from the function".  Can you advise me on this or
another method?

Thanks,
Kevin

func! DebugLine()
 normal O<esc>
 call setline( line("."), "print \"debug: line " . line(".") . "
here\\n\";")
endfunc


Reply | Threaded
Open this post in threaded view
|

Re: advice on global

Eric Arnold

Have you tried   \=  for the substitute command?  I.e.

g/debug/ s/\(debug: line \)\d\+/\=( submatch(1) . line(".") )/




--- Kevin <[hidden email]> wrote:

> Hi,
>
> I'm writing the function below to insert a line in a perl script.  The line
> contains the line number that it's on.  I want to add a command to the
> function that updates the previous calls to the function by means of a
> global command, but getting nowhere with the syntax.  Something like:
> g/debug/exe "line 4 from the function".  Can you advise me on this or
> another method?
>
> Thanks,
> Kevin
>
> func! DebugLine()
>  normal O<esc>
>  call setline( line("."), "print \"debug: line " . line(".") . "
> here\\n\";")
> endfunc
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: advice on global

Kevin-8

----- Original Message -----
From: "Eric Arnold" <[hidden email]>
To: "Kevin" <[hidden email]>; <[hidden email]>
Sent: Saturday, June 04, 2005 12:09 AM
Subject: Re: advice on global


>
> Have you tried   \=  for the substitute command?  I.e.
>
> g/debug/ s/\(debug: line \)\d\+/\=( submatch(1) . line(".") )/

That works!  It didn't occur to me to use the s/ cmd.  It seems obvious now.


> --- Kevin <[hidden email]> wrote:
>> Hi,
>>
>> I'm writing the function below to insert a line in a perl script.  The
>> line
>> contains the line number that it's on.  I want to add a command to the
>> function that updates the previous calls to the function by means of a
>> global command, but getting nowhere with the syntax.  Something like:
>> g/debug/exe "line 4 from the function".  Can you advise me on this or
>> another method?
>>
>> Thanks,
>> Kevin
>>
>> func! DebugLine()
>>  normal O<esc>
>>  call setline( line("."), "print \"debug: line " . line(".") . "
>> here\\n\";")
>> endfunc
>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: advice on global

Matthew Winn
In reply to this post by Kevin-8
On Fri, Jun 03, 2005 at 11:44:36PM -0500, Kevin wrote:
> I'm writing the function below to insert a line in a perl script.  The line
> contains the line number that it's on.  I want to add a command to the
> function that updates the previous calls to the function by means of a
> global command, but getting nowhere with the syntax.  Something like:
> g/debug/exe "line 4 from the function".  Can you advise me on this or
> another method?

An alternative approach, if I understand what you're trying to do
correctly, is to get the line number for debug messages from Perl
itself.  Put a call to "debug();" (below) at suitable places in the
program to get a backtrace.  Adapt as required.

sub debug {
    my $i = 0;
    while (my @c = caller($i)) {
        print "$i: in $c[3], called from $c[1]:$c[2]\n";
        $i++
    }
}

--
Matthew Winn ([hidden email])