# In Perl, I type: %some_hash, $some_scalar, @some_list, some_func() # and then hit Ctrl-K to turn it into: print STDERR "DBG 950($$): ([\%some_hash, \$some_scalar, \@some_list, some_func()]):\n\t", Dumper([\%some_hash, $some_scalar, \@some_list, some_func()]); #### nmap !!print_perl_debug STDERR %:w #### #!/usr/bin/perl -w $handle = shift || 'STDERR'; $file = shift || '/dev/null'; $is_php = system(q(grep -q '^<\?PHP$' ) . $file) == 0; if ($is_php) { while () { chomp; s/(^\s*)//; $space = $1; $rand = int(rand 900) + 100; print qq(${space}print 'DBG $rand: $_: ' . "[$_]\\n";\n); } } else { $do_use = system "grep -q '^[^#]*use Data::Dumper' $file"; while () { chomp; s/(^\s*)//; $space = $1; $use = $do_use ? " use Data::Dumper;" : ''; s/([@%])/\\$1/g; s/\$\\\@/\$\@/g; # fix up $@ $_ = "[$_]" if /,/; $rand = int(rand 900) + 100; $printable = $_; $printable =~ s/(\$|")/\\$1/g; my $last = /\S/ ? qq(($printable):\\n\\t", Dumper($_);$use\n) : qq(\\n";\n); print $space, 'print ', ($handle eq 'STDOUT' ? '' : "$handle "), qq{"DBG $rand(\$\$): $last}; } }