Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

$0 in perl pod, not expanding to script name

by spatterson (Pilgrim)
on Jul 16, 2018 at 07:48 UTC ( [id://1218536]=perlquestion: print w/replies, xml ) Need Help??

spatterson has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script containing some brief documentation in pod format. Normally (or at least outside of perlpod) $0 is the script name, but in perlpod, $0 is output literally as '$0'.

Is there any way I can dynamically access the current script name inside perlpod? I'm returning to perl after a few years on PHP & can vaguely remember doing something similar in the past.

  • Comment on $0 in perl pod, not expanding to script name

Replies are listed 'Best First'.
Re: $0 in perl pod, not expanding to script name
by tobyink (Canon) on Jul 16, 2018 at 08:26 UTC

    Pod is a markup language, not a programming language. While markup languages can sometimes have things like macros and variables in them, pod doesn't. It's super simple. So, long story short, pod doesn't have what you want.

    However, you could use a templating module to output your pod from a template, and use that to do variable substitution.

Re: $0 in perl pod, not expanding to script name
by thanos1983 (Parson) on Jul 16, 2018 at 08:01 UTC

    Hello spatterson,

    Can you provide us a small sample of script that replicates the case that you are mentioning?

    #!/usr/bin/perl use strict; use warnings; =pod =head1 DESCRIPTION This script can have 2 parameters. The name or address of a machine and a command. It will execute the command on the given machine and print the output to the screen. =cut print "Here comes the name of the script ... $0\n"; __END__ $ perl test.pl Here comes the name of the script ... test.pl

    Looking forward to your update.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      Stripped down to the minimum, my code is this: I simply want the first $0 (inside perlpod) to output the script name
      =pod Usage: C<$0> =cut $arg = shift(); if (defined($arg) && $arg eq '-h') { print `pod2text $0`; }

        In that case, just post-process it:

        =pod Usage: C<$0> =cut $arg = shift(); if (defined($arg) && $arg eq '-h') { for (`pod2text $0`) { s/\$0/$0/; print; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found