On Thu, Mar 13, 2008 at 7:09 PM, Kenneth Wolcott
<[EMAIL PROTECTED]> wrote:
> Hi;
>
> What is the perl equivalent of a #!/bin/bash -xv?
>
> I'd like to have verbose (print each line prior to execution) and expand
> each variable prior to execution while executing?
>
> How do I run perl in debug mode non-interactively, dumping every variable
> when it gets modified?
>
> How do I get the answers to either or both of these questions using
> perldoc?
>
> Is there a perl builtin to do this? If not is there a cpan module to do
> this? If so, how would I effectively search cpan for a topic such as this?
>
>
> Thanks,
> Ken Wolcott
>
The closest I have gotten to this is the Devel::ebug* module on CPAN.
What follows is a program I wrote with it to give a set-x-like
functionality to Perl scripts. Given this script:
#!/usr/bin/perl
use strict;
use warnings;
my $i = 1;
my $j = 10;
$i++;
for (0 .. 5) {
$i++;
$j++;
}
it produces
+++ file:q.pl line: 6
+ use strict;
+ use warnings;
+
+> my $i = 1;
+ my $j = 10;
+
+ $i++;
+++ file:q.pl line: 7
++ $i = 1
+ use warnings;
+
+ my $i = 1;
+> my $j = 10;
+
+ $i++;
+
+++ file:q.pl line: 9
++ $i = 1
++ $j = 10
+ my $i = 1;
+ my $j = 10;
+
+> $i++;
+
+ for (0 .. 5) {
+ $i++;
+++ file:q.pl line: 11
++ $i = 2
++ $j = 10
+
+ $i++;
+
+> for (0 .. 5) {
+ $i++;
+ $j++;
+ }
+++ file:q.pl line: 12
++ $i = 2
++ $j = 10
+ $i++;
+
+ for (0 .. 5) {
+> $i++;
+ $j++;
+ }
+++ file:q.pl line: 13
++ $i = 3
++ $j = 10
+
+ for (0 .. 5) {
+ $i++;
+> $j++;
+ }
+++ file:q.pl line: 12
++ $i = 3
++ $j = 11
+ $i++;
+
+ for (0 .. 5) {
+> $i++;
+ $j++;
+ }
+++ file:q.pl line: 13
++ $i = 4
++ $j = 11
+
+ for (0 .. 5) {
+ $i++;
+> $j++;
+ }
+++ file:q.pl line: 12
++ $i = 4
++ $j = 12
+ $i++;
+
+ for (0 .. 5) {
+> $i++;
+ $j++;
+ }
+++ file:q.pl line: 13
++ $i = 5
++ $j = 12
+
+ for (0 .. 5) {
+ $i++;
+> $j++;
+ }
+++ file:q.pl line: 12
++ $i = 5
++ $j = 13
+ $i++;
+
+ for (0 .. 5) {
+> $i++;
+ $j++;
+ }
+++ file:q.pl line: 13
++ $i = 6
++ $j = 13
+
+ for (0 .. 5) {
+ $i++;
+> $j++;
+ }
+++ file:q.pl line: 12
++ $i = 6
++ $j = 14
+ $i++;
+
+ for (0 .. 5) {
+> $i++;
+ $j++;
+ }
+++ file:q.pl line: 13
++ $i = 7
++ $j = 14
+
+ for (0 .. 5) {
+ $i++;
+> $j++;
+ }
+++ file:q.pl line: 12
++ $i = 7
++ $j = 15
+ $i++;
+
+ for (0 .. 5) {
+> $i++;
+ $j++;
+ }
+++ file:q.pl line: 13
++ $i = 8
++ $j = 15
+
+ for (0 .. 5) {
+ $i++;
+> $j++;
+ }
#!/usr/bin/perl
use strict;
use warnings;
use Devel::ebug;
use Data::Dumper;
my $ebug = Devel::ebug->new;
$ebug->program(shift);
$ebug->load;
until ($ebug->finished) {
print "+++ file:", $ebug->filename, " line: ", $ebug->line, "\n";
my $pad = $ebug->pad;
for my $var (sort keys %$pad) {
if (ref $pad->{$var}) {
for my $line (split /\n/,
Data::Dumper->Dump([$pad->{$var}], [$var])) {
print "++ $line\n";
}
} else {
print "++ $var = $pad->{$var}\n";
}
}
for my $line ($ebug->codelines($ebug->line-3 .. $ebug->line-1)) {
next unless defined $line;
print "+ $line\n";
}
print "+> ", $ebug->codeline, "\n";
for my $line ($ebug->codelines($ebug->line+1 .. $ebug->line+3)) {
next unless defined $line;
print "+ $line\n";
}
$ebug->step;
}
* http://search.cpan.org/~lbrocard/Devel-ebug-0.48/lib/Devel/ebug.pm
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/