• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 784
  • Last Modified:

Perl script

I am a newer of writing perl script. What is Getopts for? Can you explain the following script? Thanks!
&Getopts ( "d:s:i:f:r:h" ) ;
 if ( defined ( $opt_h ) )
{
    &print_help_msg ;
    exit ( 1 ) ;
}
0
luyan
Asked:
luyan
3 Solutions
 
luyanAuthor Commented:
I found "getopts" command are processes command-line arguments and checks for valid options. I  know what &Getopts ( "d:s:i:f:r:h" )  means now. Do you know any good online documents for learning perl and checking commands in perl scripting?
Thanks!
0
 
Adam314Commented:
Online documentation for perl:
http://perldoc.perl.org

Tutorials at above site:
http://perldoc.perl.org/index-tutorials.html

To get documentation on modules:
http://search.cpan.org/
0
 
luyanAuthor Commented:
Nice documentation. It's handy! Thanks!
Can you explain the following script when choosing the option "d"?     Thanks!
&Getopts ( "d:s:i:f:r:h" ) ;
if ( defined ( $opt_d ) )
{
    $Object[0][1] = $opt_d ;
    if ( defined $COMMONDBS{$Object[0][1]} ) {
       $Object[0][4] = $COMMONDBS{$Object[0][1]} ; }
    else {
       $Object[0][4] = $Object[0][1] ;
print $Object[0][4]; }
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
TintinCommented:
All the perl documention should be on your computer

perldoc Getopt::Std

0
 
TintinCommented:
In the following code:

&Getopts ( "d:s:i:f:r:h" ) ;
if ( defined ( $opt_d ) )
{
    $Object[0][1] = $opt_d ;
    if ( defined $COMMONDBS{$Object[0][1]} ) {
       $Object[0][4] = $COMMONDBS{$Object[0][1]} ; }
    else {
       $Object[0][4] = $Object[0][1] ;
print $Object[0][4]; }
}

if you invoke the script with

script -d foobar

then $Object[0][1] gets set to 'foobar'

Then if the hash $COMMONDBS{foobar} exists, then set $Object[0][4] to the value of the hash.

All seems like very convoluted code and rather cryptic variable names and structures.
0
 
marchentCommented:
if you want to read -s and -e from commandline.
sub read_param
{
      my %opts;
      
      getopts('s:e:',\%opts);
      
      if($opts{'s'})
      {
            $s = $opts{'s'};
      }
      if($opts{'e'})
      {
            $e = $opts{'e'};
      }
      return;
}
0
 
luyanAuthor Commented:
Do you have any good idea on debugging perl script?
0
 
ozoCommented:
perldoc perldebug
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now