> Hello together,
> I have another problem with arguments and switches as options for a
process.
> I want one switch and several arguments to call the process. 
> Example: kermit.pl -v thunder.txt compare.txt
> 
> I try to implement this actually with a hash:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use File::Copy;
> use Getopt::Std;
> 
> my %option = ();
> getopts ("vp:", \%option );
> 
> our ( $opt_v, $opt_p );
> #our $searchpattern = %option{p};
> our $input;
> our $searchpattern;
> 
> 
> if ( $option{v} )
> {
>  print "The searchpattern ist: $searchpattern and the input $input \n";
> }
> .....
> 
> So far it should work. But I get this output:
> Name "main::opt_p" used only once: possible typo at ./kermit.pl line 14.
> Use of uninitialized value in concatenation (.) or string at
./kermit.pl line 
> 20.
> Use of uninitialized value in concatenation (.) or string at
./kermit.pl line 
> 20.
> The searchpattern ist:     and the input
> 
> What is the problem? 
> 
> Thank you.
> 
> Gruss Christian
> 

Um, there isn't one? Perl is just warning you that you are trying to use
two variables which do not yet have values, and that you declared a
variable that isn't used anywhere else and is worried it is named wrong,
otherwise why else would you have declared it?  The output looks fine
for the switches you provided, but even if you did provide a pattern you
are printing $searchpattern, instead of $option{'p'}, and $searchpattern
 is never assigned a value.

Tell us what you are *really* trying to do.  May I also suggest using
Getopt::Long instead, and you may wish to start with a template, I have
one prepared at:

http://danconia.org/cgi-bin/request?handler=Content;content=StaticPage;label=getopt_long_template

You should also review the docs,

perldoc Getopt::Std
perldoc Getopt::Long

And you should pick one strategy, global variabls (aka C<our $opt_v>), a
hash, or object based, and stick with it, rather than trying to use
multiple at the same time.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to