Mysterious perl -d switch and $ENV{'PERL5DB'} problems 
Author Message
 Mysterious perl -d switch and $ENV{'PERL5DB'} problems

Perhaps someone out there can help me with this.

I want to make a tags utility available to the Perl community, and I
can't get it working.

I've written a little Perl tags utility that uses the Perl de{*filter*}
support. The body of the tags utility is in the DB::DB routine:

---------cut ------

sub DB::DB
{
        sub DB::keySort
        {
                my ($aPackage, $aTag) = $a =~ m{(.*)::(\w+)};
                my ($bPackage, $bTag) = $b =~ m{(.*)::(\w+)};
                $aPackage cmp $bPackage
                        or $aTag eq 'BEGIN' ? -1 : 0
                        or $bTag eq 'BEGIN' ? 1 : 0
                        or $aTag cmp $bTag;
        }

        foreach my $key (sort DB::keySort keys(%DB::sub))
        {
                my ($fileName, $lineNumber) = $DB::sub{$key} =~
m{(.+):(\d+)-\d+};
                my ($package, $tag) = $key =~ m{(.*)::(\w+)};

                my $line = $$lines[$lineNumber];
                if ($tag eq 'BEGIN')
                {
                        # back up till the package line
                        while ($line !~ m{\bpackage\s+} and $lineNumber > 0)
                        {
                                $lineNumber--;
                                $line = $$lines[$lineNumber];
                                redo if !$line; # pod lines are undef'd
                        }
                        $key = $package;
                }
                chomp($line);
                $line =~ s{[\/]}{\\$&}g;
                print "$key\t$fileName\t/^$line\$/\n";
        }
        exit;

Quote:
}

--------- cut ------

Now, this works fine when I put it in devel/nptags.pm (with a "1;" as
the last line) and go:

        perl -d:nptags someprogram.pl

It also works fine when I put it in a separate file (also with a "1;"
as the last line) and go (using the Korn Shell):

        PERL5DB="BEGIN { require 'nptags.pm' }"  perl -d someprogram.pl

But it does not work fine when I take the entire contents of the above
routine and put it into the PERL5DB environment variable and run perl:

        PERL5DB=$(< nptags.pm)
        perl -d someprogram.pl

It complains:
        No DB::DB routine defined at someprogram.pl line 1.

The reason I wanted to do this was that I wanted to package the above
DB::DB routine and a driver program into a single perl utility:

----------- cut -------

#! perl -w
$/ = undef;
$ENV{PERL5DB} = <DATA>;

while (my $fileName = shift)
{
        system $^X, '-d', $fileName;

Quote:
}

__DATA__

sub DB::DB
{
        # as above

Quote:
}

----------- cut -------

Now, I've tried various versions of the above, using

BEGIN { sub DB::DB { ... } }

and

{ sub DB::DB { ... } }

but can't get it to work. What am I missing?

BTW, I'm on Windows/NT. My perl -v output:

This is perl, version 5.005_02 built for MSWin32-x86-object
(with 1 registered patch, see perl -V for more detail)

Binary build 509 provided by ActiveState Tool Corp.
http://www.*-*-*.com/ Built 13:37:15 Jan  5 1999

Thanks,
Ned Konz



Wed, 11 Jul 2001 03:00:00 GMT  
 Mysterious perl -d switch and $ENV{'PERL5DB'} problems
[A complimentary Cc of this posting was sent to Ned Konz


Quote:
> Perhaps someone out there can help me with this.

> I want to make a tags utility available to the Perl community, and I
> can't get it working.

> I've written a little Perl tags utility that uses the Perl de{*filter*}
> support. The body of the tags utility is in the DB::DB routine:

...

Quote:
> Now, this works fine when I put it in devel/nptags.pm (with a "1;" as
> the last line) and go:

>    perl -d:nptags someprogram.pl

> It also works fine when I put it in a separate file (also with a "1;"
> as the last line) and go (using the Korn Shell):

>    PERL5DB="BEGIN { require 'nptags.pm' }"  perl -d someprogram.pl

> But it does not work fine when I take the entire contents of the above
> routine and put it into the PERL5DB environment variable and run perl:

>    PERL5DB=$(< nptags.pm)
>    perl -d someprogram.pl

> It complains:
>    No DB::DB routine defined at someprogram.pl line 1.

This


works here (5.005_53).  Are you sure you do not need to write it as

      PERL5DB="$(< nptags.pm)"

Ilya



Thu, 12 Jul 2001 03:00:00 GMT  
 Mysterious perl -d switch and $ENV{'PERL5DB'} problems
[A complimentary Cc of this posting was sent to Ned Konz


...

Quote:
> Now, this works fine when I put it in devel/nptags.pm (with a "1;" as
> the last line) and go:

>    perl -d:nptags someprogram.pl

> It also works fine when I put it in a separate file (also with a "1;"
> as the last line) and go (using the Korn Shell):

>    PERL5DB="BEGIN { require 'nptags.pm' }"  perl -d someprogram.pl

> But it does not work fine when I take the entire contents of the above
> routine and put it into the PERL5DB environment variable and run perl:

Experiments (and a walk through using C de{*filter*}) show that Perl fails
if PERL5DB contains "\n" (whatever is after the first "\n" - including
the generated code to handle -n and -p switches! - is ignored).

It is possible to fix this, but the fix will include creating a new
"source filter" - which looks a little bit too much, especially since
you can do

    PERL5DB='BEGIN { eval $ENV{PERL5DB_LONG} }'

Patches to documentation are welcome.

Ilya



Fri, 13 Jul 2001 03:00:00 GMT  
 Mysterious perl -d switch and $ENV{'PERL5DB'} problems

Quote:
> Experiments (and a walk through using C de{*filter*}) show that Perl fails
> if PERL5DB contains "\n" (whatever is after the first "\n" - including
> the generated code to handle -n and -p switches! - is ignored).
> you can do

>     PERL5DB='BEGIN { eval $ENV{PERL5DB_LONG} }'
> Patches to documentation are welcome.

Hmm, on the second thought, since you can do it, Perl could do it
itself.  Currently Perl puts the contents of PERL5DB into the
"next_source_line" variable, it could put the string

   BEGIN { eval $ENV{PERL5DB} }

instead.  Any volunteers for a patch?

Ilya



Fri, 13 Jul 2001 03:00:00 GMT  
 Mysterious perl -d switch and $ENV{'PERL5DB'} problems
[posted and emailed]


Quote:
> Hmm, on the second thought, since you can do it, Perl could do it
> itself.  Currently Perl puts the contents of PERL5DB into the
> "next_source_line" variable, it could put the string

>    BEGIN { eval $ENV{PERL5DB} }

> instead.  Any volunteers for a patch?

I'll take a shot at it.  From what I've seen (using the new ctags :)
it's a one line change in toke.c.  However, I have a few questions:

1) Do we patch 5.005_54 or 5.005_02_m4?
2) Ilya, will you help me test it and write code for the test harness?

Colin



Sat, 14 Jul 2001 03:00:00 GMT  
 Mysterious perl -d switch and $ENV{'PERL5DB'} problems
[posted and mailed]

Quote:

> I'll take a shot at it.  From what I've seen (using the new ctags :)
> it's a one line change in toke.c.  However, I have a few questions:

> 1) Do we patch 5.005_54 or 5.005_02_m4?

_54.  Essentially, if you are ever unsure as to which branch a
patch should be generated against you should use the latest
release along the dev track.

I added some stuff to patching.pod about this, but it hasn't
had time to show up in the releases (well, it's in the new trial of
_03, but that doesn't count :-).  

dgris
--





Sat, 14 Jul 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. HELP: Can't get debugger to work - perl can't find perl5db.pl

2. HELP: Can't get debugger to work - perl can't find perl5db.pl

3. HELP: Can't get debugger to work - perl can't find perl5db.pl

4. ENV{'REMOTE_USER'} problem

5. $ENV{'REMOTE_HOST'} Problem on NT

6. Problem: With the $ENV{'blah'} variable

7. mysterious '1' appearing

8. Mysterious 'utf8_length: unaligned end' error

9. Mysterious 'pp000040' files from BigPerl

10. Mysterious 'pp000040' files from BigPerl

11. How to set 'env'-var in perl

12. $ENV{'AUTH_TYPE'} and $ENV{'REMOTE_USER'}

 

 
Powered by phpBB® Forum Software