pauamma: Cartooney crab holding drink ("Cartooney crab holding drink")pauamma ([personal profile] pauamma) wrote in [site community profile] dw_dev_training,
@ 2010-08-31 06:34 pm UTC
Entry tags:perl, tips
Context was someone asking why
print "Hello, world!\n" && die;
doesn't output anything. Someone replied with a nifty trick to help figure this out:
perl -MO=Deparse -e 'print "Hello, world!\n" && die;'
(go ahead and try it in your Dreamhack).


(6 comments) - (Post a new comment)
(Flat) (Top-level comments only)

sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (skype, sophie, weemee)


[personal profile] sophie
2010-08-31 11:38 pm UTC (link)
Also, if you need to do this trick but don't know what the operator precedence is, you can add ",-p" after the "Deparse" in order to get Perl to print parentheses to show exactly how things get calculated.

One thing, btw - this won't work as a built-in code beautifier because you'll find that some string literals aren't kept; they're transformed to '???'. That's because it's a constant value that Perl optimised away for whatever reason. (The perldoc for B::Deparse explains more.)

(Reply to this


pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Martin)


[personal profile] pne
2010-09-01 06:18 am UTC (link)
B::Deparse is really fun.

Have you thought about cross-posting this to [community profile] command_liners?

(Reply to this)  (Thread


afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (afuna, cats)


[personal profile] afuna
2010-09-01 10:27 am UTC (link)
Oh neat.

(What is the O for? I can find -M in man perlrun, but I can't find -O)

(Reply to this)  (Thread


alierak: (default)


[personal profile] alierak
2010-09-01 01:28 pm UTC (link)
It's the argument to -M. "perldoc O" should do something.

(Reply to this)  (Thread from start)  (Parent)  (Thread


afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (afuna, cats)


[personal profile] afuna
2010-09-02 05:45 am UTC (link)
Oh dur. So obvious now, thanks!

(Reply to this)  (Thread from start)  (Parent



(6 comments) - (Post a new comment)
(Flat) (Top-level comments only)