http://www.perlmonks.org?node_id=1080920

another CUFP or better WICDWMBP (what i can do with my baby Perl)..
Reading this post i'm started wondering if there was a way to wrap an existing script and grab modules it uses without exucuting it.
Obviously the answer or part of it was in the monastery: here
I very liked the
perl -d:Modlist=options script.pl perl -MDevel::Modlist=options script.pl # equivalent
part but, unfortunately it executes the script.pl
Also liked the tachyon-II hack, but you have to edit the script.pl and i'm too lazy.
No hope to use $^C = 1 as pointed wisely by shmem

The UNITCHECK do the trick! Never known it seems quite usefull for this task: read about it

#!perl #use strict; #commented to not pollute %INC #use warnings;#commented to not pollute %INC my $file = $ARGV[0]; my $content = do { open my $fh, '<', $file or die $!; local $/; <$fh> +}; my $begin =<<'THEEND'; UNITCHECK { no strict; # access $VERSION by symbolic reference no warnings qw (uninitialized); print map { s!/!::!g; s!.pm$!!; sprintf "%-20s %s\n", $_, ${"${_}::VERSION"} } sort keys %INC; exit; }; THEEND eval $begin.$content; print $@ if $@;
Enjoy the results!
HtH
L*

UPDATE 9 april 2014: BE CAREFULL, as stated by davido and also by LanX in other post, BEGIN blocks are executed anyway. In fact BEGIN blocks come first, in order of definition, then come UNITCHECK blocks and, being that block prepended to the original code in the above program, it will be executed just after the last BEGIN block and just before any UNITCHECK defined in the original program passed in via @ARGV. In the case of perl -c -d:TraceUse script.pl all the BEGIN UNITCHECK CHECK blocks are executed.

Here two examples to demonstrate where the -c ends his operations (a simplified version of 16 pillars of wisdom):
perl -c -e "BEGIN{print qq(1-begin\n)}; UNITCHECK {print qq(2-unitcheck\n)}; CHECK {print qq(3-check\n)}; INIT {print qq(4-init\n)}; print qq(5-main\n); END{print qq(6-end\n)}" __OUTPUT__ 1-begin 2-unitcheck 3-check -e syntax OK # the same code without -c __OUTPUT__ 1-begin 2-unitcheck 3-check 4-init 5-main 6-end
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.