Sudarshan Raghavan wrote:

> On 5 Sep 2002, Chuck Belcher wrote:
> 
>         @scalars_used{/(\$\w+)/g} = ();
>         print Dumper(\%scalars_used);
> }
> print Dumper(\%scalars_used);

this is not going to work well. consider:

#!/usr/bin/perl -w
use strict;

=item whatever
$w $x $y $z
=cut

#-- $a $b $c $d
print "hello world\n";

__END__

these aren't used at all. the problem is probably more challenge than you 
first think. how about:

#!/usr/bin/perl -w
use strict;

my %vars;

open(PROG,'foo.pl') || die $!;
while(<PROG>){
        chomp;
        #-- ignore pod
        if(/^=.+/){
                while(<PROG>){
                        chomp;
                        last if(/^=cut$/);
                }
        }
        s/#.*//; #-- ignore $this
        @vars{/[^\\](\$\w+)/g} = (); #-- don't capture print "\$hi"
}
close(PROG);

foreach my $var (keys %vars){
        print "$var\n";
}

__END__

the above is far from perfect. condiser:

print '$hi';
print 'abcd $hi abcd';
print <<'hi'
$a
$b
$c
hi
print qw{$hi $hello};
...etc etc

these aren't variables but the above code will consider them to be which is 
bad.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to