Gregg wrote:
> > I have a debug log subroutine that I copy and paste into different
> > Perl modules as I am working on them. It occurred to me that it would
> > be very useful to log the line numbers to the file as a better means
> > of keeping track of what a script is doing, and finding the location
> > using the vi editor. This might be a stupid question or simply one
> > for some genius out there to answer:
>
>
> I would like something like
>
>
> #!/usr/bin/perl -w
>
> ---- code ----
>
> &DebugLog("I am at line: $line_number_in_the_script");
>
> --- more code -----
>
>
> Sub DebugLog()
> {
> my ($line) = @_;
> print "$line\n";
>
> }
>
>
> I could paste these throughout my code and not worry about where they
> end up.
>
> Any ideas?
Not a strange question at all. Do it like this (but then you must
remember to tell us which is source line #433 when you come
back for help!)
Cheers,
Rob
#!/usr/bin/perl -w
use strict;
#---- code ----
&DebugLog;
#--- more code -----
sub DebugLog {
my @caller = caller;
printf "DebugLog at %s line %d.\n", @caller[1,2];
}
output
DebugLog at E:\Perl\source\brazil.pl line 5.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]