Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Pod Usage Example

7 views
Skip to first unread message

Kelvin Philip

unread,
Dec 23, 2008, 9:46:43 AM12/23/08
to Mr. Shawn H. Corey, begi...@perl.org
Hi,

Thanks for the help :-)

When I call pod2usage(verbose => 2); the terminal is getting stuck. When I
press CTRL+4, it comes out and displays the whole man page. Would you pls
suggest a solution for this issue?

Regards,
Kelvin Philip

On Tue, Dec 23, 2008 at 6:54 PM, Mr. Shawn H. Corey <shawn...@magma.ca>wrote:

> On Tue, 2008-12-23 at 13:29 +0530, Kelvin Philip wrote:
> > Hi,
> >
> > Would someone guide me with a simple example for perl documentation using
> > Pod :: Usage?
>
> # Documentation levels
> my $DOC_USAGE = 0;
> my $DOC_HELP = 1;
> my $DOC_VER = 2;
> my $DOC_MAN = 3;
>
> # --------------------------------------
> # Subroutines
>
> # --------------------------------------
> # Usage: print_documentation( $documentation_level );
> # Purpose: Print the usage, help, or man documentation.
> # Returns: Does not return.
> # Parameters: $documentation_level -- how much documentation to display.
> # 0 == usage
> # 1 == help
> # 2 == version
> # other == man
> #
> sub print_documentation {
> my $level = shift @_;
>
> # print the usage documentation
> if( $level == $DOC_USAGE ){
> pod2usage(
> -exitval => 2,
> -verbose => 99,
> -sections => 'USAGE',
> );
> }
>
> # print the help documentation
> if( $level == $DOC_HELP ){
> pod2usage(
> -exitval => 2,
> -verbose => 99,
> -sections => 'NAME|VERSION|USAGE|REQUIRED ARGUMENTS|OPTIONS',
> );
> }
>
> # print the version
> if( $level == $DOC_VER ){
> pod2usage(
> -exitval => 2,
> -verbose => 99,
> -sections => 'VERSION',
> );
> }
>
> # print the man documentation
> pod2usage(
> -exitval => 2,
> -verbose => 2,
> );
> }
>
> # --------------------------------------
> # Usage: get_cmd_opts();
> # Purpose: Process the command-line switches.
> # Returns: none
> # Parameters: none
> #
> sub get_cmd_opts {
>
> # Check command-line options
> unless( GetOptions(
> usage => sub { print_documentation( $DOC_USAGE ); },
> help => sub { print_documentation( $DOC_HELP ); },
> version => sub { print_documentation( $DOC_VER ); },
> man => sub { print_documentation( $DOC_MAN ); },
> )){
> print_documentation( $DOC_USAGE );
> }
>
> }
>
>
> --
> Just my 0.00000002 million dollars worth,
> Shawn
>
> Believe in the Gods but row away from the rocks.
> -- ancient Hindu proverb
>
>

Steve Pittman

unread,
Dec 23, 2008, 1:12:52 PM12/23/08
to Mr. Shawn H. Corey, begi...@perl.org
Does any one have a good example?

Best Regards,

Steve

Chas. Owens

unread,
Dec 23, 2008, 6:36:29 PM12/23/08
to Steve Pittman, Mr. Shawn H. Corey, begi...@perl.org
On Tue, Dec 23, 2008 at 13:12, Steve Pittman <spit...@jhmi.edu> wrote:
> Does any one have a good example?
snip

That depends on what you want to do. There are five common ways of
executing external programs (including shell scripts):

1. the system function*
2. the qx// operator**
3. the open function***
4. the open2 function from IPC::Open2****
5. the open3 function from IPC::Open3*****

Use system when you just want to execute the program and check it's
return status:

unless (system("ssh", "user@machine", "touch", "done") == 0) {
#an error occured so, deal with the return in $?
#the value is OS dependent, so read up on what your OS does in perlport
}

Use qx// when you want to easily capture the STDOUT from an external program:

my @files = qx{/usr/bin/ssh user@machine ls};

Use open when you want to capture the STDOUT from an external program
and either need to operate on it as it is written, or if it will be
very large and you don't want to hold the whole output in memory:

open my $fh, "-|", "/usr/bin/ssh", "user@machine", "find", "/"
or die "could not execute command: $!";

while (my $line = <$fh>) {
#do something with each line returned
}

Use the open2 function from IPC::Open2 when you need to write to a
program's STDIN and read from it's STDOUT.

Use open3 from IPC::Open3 when you need to write to a program's STDIN
and read from it's STDOUT and STDERR.

* http://perldoc.perl.org/functions/system.html
** http://perldoc.perl.org/perlop.html#qx/STRING/
*** http://perldoc.perl.org/functions/open.html
**** http://perldoc.perl.org/IPC/Open2.html
***** http://perldoc.perl.org/IPC/Open3.html


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Filip van der Meeren

unread,
Dec 24, 2008, 5:18:37 AM12/24/08
to John W. Krahn, Perl Beginners

On 24 Dec 2008, at 02:24, John W. Krahn wrote:

> Chas. Owens wrote:
>> On Tue, Dec 23, 2008 at 13:12, Steve Pittman <spit...@jhmi.edu>
>> wrote:
>>> Does any one have a good example?
>> snip
>> That depends on what you want to do. There are five common ways of
>> executing external programs (including shell scripts):
>> 1. the system function*
>> 2. the qx// operator**
>> 3. the open function***
>> 4. the open2 function from IPC::Open2****
>> 5. the open3 function from IPC::Open3*****
>

Five ways?
You forgot the backtick:

my $result = `Some shell command`;

> Don't forget:
>
> perldoc -f exec
> perldoc Shell
> http://search.cpan.org/~adamk/IPC-Run-0.82/
>
>
>
> John
> --
> Those people who think they know everything are a great
> annoyance to those of us who do. -- Isaac Asimov
>
> --
> To unsubscribe, e-mail: beginners-...@perl.org
> For additional commands, e-mail: beginne...@perl.org
> http://learn.perl.org/
>
>


Filip van der Meeren
fi...@code2develop.com

0 new messages