Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Printing POD info to terminal window without exiting

by haukex (Archbishop)
on Aug 08, 2021 at 18:28 UTC ( [id://11135703]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Printing POD info to terminal window without exiting
in thread Printing POD info to terminal window without exiting

Pod::Usage seems to rely on underlying "formatters", including perldoc.

What's your point here? If you think Pod::Usage is running an external command, you're mistaken. Oversimplifying a bit, the family of Pod::* modules in the core do use each other, so that Pod::Usage and Pod::Perldoc can use the same parser and formatters (see Pod::Simple), but when just converting some POD to text there is no need to call external commands.

Explain to me your objection. ... Does your object rely simply on ...

I already named almost all of my objections to your suggestion, and so I feel I might be being trolled, but for the sake of explanation:

system(qq{perldoc $0});

  • ... is brittle because:
    • it relies on perldoc being installed in the first place (and writing code to test for its installation, as you suggested, adds a lot of complexity that is unnecessary because you can just write use Pod::Usage; instead and get immediate, compile-time feedback in case the core modules happen to be missing),
    • it relies on perldoc being in the PATH,
    • it relies on the value of $0, which the user may have modified, and IIRC there are other cases where $0 is unreliable.
    • Update: Plus: $0 is not being quoted and will fail with whitespace or other shell metacharacters in the filename.
  • ... is insecure because it is using the single-argument system with a variable being interpolated into the string (I've linked you to Calling External Commands More Safely twice).
  • ... is not directly a solution to the OP's question because its output is different from that of Pod::Usage.

Add to that the facts that calling an external program is fairly wasteful and that the solution was already found using modules that have been in the Perl core for over 20 years, that rounds out the reasons why I objected.

Remember that this is all in the context of providing help to others, so if you've been using this in your own code then you're free to do so, but it's not something I would recommend to anyone else.

perldoc is just a Perl script, and here you said:

I swear, "shelling-out" to actual Perl scripts from a Perl script is one of the most offensive things I can see in Perl code. All the wasted cycles, dead electrons, PIDs, (oh the horror!) and server fan RPMs that are consumed for no reason

Replies are listed 'Best First'.
Re^5: Printing POD info to terminal window without exiting
by perlfan (Vicar) on Aug 09, 2021 at 01:42 UTC
    I am not trolling you, and I appreciate the thorough explanation. Regarding my quote (the recall of which is quite impressive) is predicated on the fact that one has control of the scripts themselves. However, your point's well taken. You're time's been well spent, if you consider the that you've convinced me to reconsider my original suggestion. I won't stop doing that in a pinch (I suppose until I understand the alternative more clearly), but I will give pause next time I write at tool (which is often).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-16 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found