perl deparse question.

E

ewaguespack

What does the -p do in the following line:

perl -MO=Deparse,-p

also, is there a one liner that will run deparse, and tidy on a file at
the same time? or is that stupid?

preservation of comments would be nice but isn't critical.

Thanks.
 
I

it_says_BALLS_on_your_forehead

What does the -p do in the following line:

perl -MO=Deparse,-p

also, is there a one liner that will run deparse, and tidy on a file at
the same time? or is that stupid?

preservation of comments would be nice but isn't critical.

this is not a Perl solution, but you could always create an alias in
your .profile or .<shell>rc file for running deparse and tidy.
 
I

it_says_BALLS_on_your_forehead

What does the -p do in the following line:

perl -MO=Deparse,-p


http://search.cpan.org/~nwclark/perl-5.8.8/ext/B/B/Deparse.pm

-p
Print extra parentheses. Without this option, B::Deparse includes
parentheses in its output only when they are needed, based on the
structure of your program. With -p, it uses parentheses (almost)
whenever they would be legal. This can be useful if you are used to
LISP, or if you want to see how perl parses your input. If you say

if ($var & 0x7f == 65) {print "Gimme an A!"}
print ($which ? $a : $b), "\n";
$name = $ENV{USER} or "Bob";
B::Deparse,-p will print

if (($var & 0)) {
print('Gimme an A!')
};
(print(($which ? $a : $b)), '???');
(($name = $ENV{'USER'}) or '???')
which probably isn't what you intended (the '???' is a sign that perl
optimized away a constant value).
 
I

it_says_BALLS_on_your_forehead

it_says_BALLS_on_your_forehead said:
this is not a Perl solution, but you could always create an alias in
your .profile or .<shell>rc file for running deparse and tidy.

disregard this; i think you are asking something different. you could
direct the output of the deparse to a file, and use that file as the
input for your perltidy call.
 
D

Donald King

What does the -p do in the following line:

perl -MO=Deparse,-p

also, is there a one liner that will run deparse, and tidy on a file at
the same time? or is that stupid?

preservation of comments would be nice but isn't critical.

Thanks.

The deparse documentation says that -p adds parentheses to the output,
even where they're not required. (If you're not aware, the O module is
a frontend to the compiler backends under B::*, and deparse is a backend
properly called B::Deparse. The command "perldoc B::Deparse" shows the
deparse documentation.)

If your tidy program can run as a filter (read from STDIN, write to
STDOUT), you could run it as a filter like:

perl -MO=Deparse file.pl | tidy - > deparsed.pl

Alternately, if your tidy program can't be made to run as a filter, you
could write a shell script (or even a Perl script) that saves STDIN to a
temporary file, runs the tidy program, then reads the temporary file to
STDOUT.

As far as comments go, Perl junks them before deparse even runs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top