Hi, I'm trying to write a testscript that will print all symbols that are used in another script like this:
symdump script1.pl 5 7
This will dump the symbol table after line 5 in the script and after line 7 in the script. This far I've come up with this:
#!/usr/bin/perl use strict; use warnings; use Devel::Symdump; $| = 1; my $code; my $program=shift @ARGV; die ("usage: $0 <programname> <linenr.> [<linenr.>...]\n") unless ($pr +ogram); open (PRG, $program) or die "cant open '$program'\n"; my $symdumpcode = " \$main::obj=Devel::Symdump->rnew('ThisIsAnotherPackageAndMostLikelyWil +lNeverCollideWithAnyOtherNamespace'); print \$main::obj->as_string(); "; my $idx=0; foreach my $arg (sort {$a <=> $b} @ARGV) { while (<PRG>) { $idx++; $code .= $_; last if ($arg == $idx and $code .= $symdumpcode); } } close PRG; eval "package ThisIsAnotherPackageAndMostLikelyWillNeverCollideWithAny +OtherNamespace; $code"; print $@ if ($@);
This doesn't print any symbols for my testscripts. If I change the rnew('<longpackagename>') to rnew('main') it will print all symbols including the symbols used in Devel::Symdump. Tried using the diff method in Devel::Symdump but that does only show a diff (duh), so any packages used in my script AND in Devel::Symdump will not show up. What I could do is make 2 Symdump-objects, one of the eval-ed code, one of Devel::Symdump itself, and compare their as_string output manually (it's sorted already), but that doesn't help me understand why the above code doesn't work.

My questions:

In reply to Devel::Symdump without Devel::Symdump interference by eXile

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.