Home > Archive > PERL Miscellaneous > March 2006 > perl deparse question.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
perl deparse question.
|
|
| ewaguespack@gmail.com 2006-03-30, 7:00 pm |
| 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.
| |
| it_says_BALLS_on_your_forehead 2006-03-30, 7:00 pm |
|
ewaguespack@gmail.com wrote:
> 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.
| |
| it_says_BALLS_on_your_forehead 2006-03-30, 7:00 pm |
|
ewaguespack@gmail.com wrote:
> What does the -p do in the following line:
>
> perl -MO=Deparse,-p
>
http://search.cpan.org/~nwclark/per.../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).
| |
| it_says_BALLS_on_your_forehead 2006-03-30, 7:00 pm |
|
it_says_BALLS_on_your_forehead wrote:
> ewaguespack@gmail.com wrote:
>
> 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.
| |
| Donald King 2006-03-30, 7:00 pm |
| ewaguespack@gmail.com wrote:
> 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.
--
Donald King, a.k.a. Chronos Tachyon
http://chronos-tachyon.net/
|
|
|
|
|