Re: Getopt::Long

2012-05-16 Thread Manfred Lotz
Hi Rajesh,

On Wed, 16 May 2012 16:11:13 +0530
Rajesh Saha  wrote:

> Hi,
> 
> Sorry for one typo. Read "GetOptions" in place of "Getoptions" .
> 
> Regards,
> Rajesh
> 
> 
> 

Here is how I do it:


#! /usr/bin/perl

use strict;
use warnings;

use Getopt::Long;


my $dry_run = 0;

GetOptions('version|V' => sub { version(); exit; },
   'dry-run|n' => \$dry_run,
   'help|h' => sub { usage(); },
   ) or usage();


exit;


sub version {
print "$0: Version 0.1\n";
exit;
}

sub usage {
print <<"END_USAGE"
Usage: $0 [ Options ]

This script does important work 

Options:
 -n, --dry-run  Simulates rsync commands
 -V, --version  Print version
 -h, --help This help
END_USAGE
;
exit;
  
return;
}



-- 
Manfred



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getopt::Long

2012-05-16 Thread Brandon McCaig
On Wed, May 16, 2012 at 10:56:59AM +, Michael Brader wrote:
> Hi,

Hello:

> Your problem is that Getopt::Long is consuming your -help as
> the argument to -abc before it can be recognised. You might be
> able to do something with the other Getopt::* modules, but the
> following piece of code will do what you want if you really
> need it:
> 
> use List::MoreUtils qw(any);
> use Getopt::Long;
> 
> my $abc;
> my $help;
> 
> if ( any { $_ eq '-help' } @ARGV ) {
> $help = 1;

Note that this doesn't account for '--help'. :) Besides, what if
'--help' happens to be a valid option argument? This would
prevent that from working. I think it's best to just keep with
the module's behavior and work normally. If a user wants --help
then they should generally /just/ say --help. If you want to do
some kind of option-specific help then specify --help before
--the-option:

  my-command --help --the-option

Or use non-option subcommands:

  my-command subcommand --help

Regards,


-- 
Brandon McCaig  
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'



signature.asc
Description: Digital signature


RE: Getopt::Long

2012-05-16 Thread Michael Brader
Hi,

Your problem is that Getopt::Long is consuming your -help as the argument to 
-abc before it can be recognised. You might be able to do something with the 
other Getopt::* modules, but the following piece of code will do what you want 
if you really need it:

use List::MoreUtils qw(any);
use Getopt::Long;

my $abc;
my $help;

if ( any { $_ eq '-help' } @ARGV ) {
$help = 1;
}

GetOptions (
"abc=s" => \$abc,
"help" => \$help
);

if ( $help ) { print "This is help message\n" ; exit ;}

if ($abc) { print "You have choosen \"abc\" as $abc" };

# ==

If you don't have List::MoreUtils installed and can't install it, replace the 
'if ( any...)' block with:

foreach my $arg (@ARGV) {
if ( $arg eq '-help' ) {
$help = 1;
last;
}
}

Cheers,
Michael

-- 
Michael Brader
Senior Software Engineer - Billing
Techops - Softdev
Internode http://www.internode.on.net/


From: Rajesh Saha [rajeshsaha...@gmail.com]
Sent: Wednesday, 16 May 2012 6:39 PM
To: beginners@perl.org
Subject: Getopt::Long

Hi,

In my program, I am using the module Getopt::Long

My intension is that if the user chooses "--help", the program should show
the help message without bothering whether other options has been used or
not.

My program (say, test.pl) :

use Getopt::Long
my $abc;
my $help;

Getoptions ( "abc=s" => \$abc,
   "help" => \$help
 );

if ($help) { print "This is help message\n" ; exit ;}

if ($abc) { print "You have choosen \"abc\" as $abc" };


If I run this:

1.test.pl -help
Output: This is help message

2. test.pl -abc ABC
Output : You have choosen abc as ABC

3. test.pl -abc -help
Output: You have choosen abc as -help

Out the above results 1 & 2 are fine, but 3 is not as I want. I understand
what's happening here [$abc is assigned as "-help"], but don't have idea
how to implement it properly so that in the 3rd it would print like " This
is help message" .

Can anybody help please ?


Thanks n regards
Rajesh Saha

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getopt::Long

2012-05-16 Thread Rajesh Saha
Hi,

Sorry for one typo. Read "GetOptions" in place of "Getoptions" .

Regards,
Rajesh



On Wed, May 16, 2012 at 2:39 PM, Rajesh Saha wrote:

> Hi,
>
> In my program, I am using the module Getopt::Long
>
> My intension is that if the user chooses "--help", the program should show
> the help message without bothering whether other options has been used or
> not.
>
> My program (say, test.pl) :
>
> use Getopt::Long
> my $abc;
> my $help;
>
> Getoptions ( "abc=s" => \$abc,
>"help" => \$help
>  );
>
> if ($help) { print "This is help message\n" ; exit ;}
>
> if ($abc) { print "You have choosen \"abc\" as $abc" };
>
>
> If I run this:
>
> 1.test.pl -help
> Output: This is help message
>
> 2. test.pl -abc ABC
> Output : You have choosen abc as ABC
>
> 3. test.pl -abc -help
> Output: You have choosen abc as -help
>
> Out the above results 1 & 2 are fine, but 3 is not as I want. I understand
> what's happening here [$abc is assigned as "-help"], but don't have idea
> how to implement it properly so that in the 3rd it would print like " This
> is help message" .
>
> Can anybody help please ?
>
>
> Thanks n regards
> Rajesh Saha
>
>


Getopt::Long

2012-05-16 Thread Rajesh Saha
Hi,

In my program, I am using the module Getopt::Long

My intension is that if the user chooses "--help", the program should show
the help message without bothering whether other options has been used or
not.

My program (say, test.pl) :

use Getopt::Long
my $abc;
my $help;

Getoptions ( "abc=s" => \$abc,
   "help" => \$help
 );

if ($help) { print "This is help message\n" ; exit ;}

if ($abc) { print "You have choosen \"abc\" as $abc" };


If I run this:

1.test.pl -help
Output: This is help message

2. test.pl -abc ABC
Output : You have choosen abc as ABC

3. test.pl -abc -help
Output: You have choosen abc as -help

Out the above results 1 & 2 are fine, but 3 is not as I want. I understand
what's happening here [$abc is assigned as "-help"], but don't have idea
how to implement it properly so that in the 3rd it would print like " This
is help message" .

Can anybody help please ?


Thanks n regards
Rajesh Saha


Re: Getopt::Long in perl

2010-07-29 Thread Jim Gibson
On 7/29/10 Thu  Jul 29, 2010  1:17 AM, "Sooraj S"
 scribbled:

> Hi,
> 
> I am using Getopt::Long to accept the command line arguments.
> 
> Logic
> -
> I have two mandatory options.
> 1.mod1_num
> 2.mod2_num
> 
> Both of them can accept either a 3digit number or another parameter
> "preserve" which inturn accepts a 3digit number.
> 
> eg: my_script -mod1_num 123 -mod2_num 234
>   my_script -mod1_num -preserve 123 mod2_num 234
> 
> If "preserve" is used with "mod1_num" it cannot be used with
> "mod2_num" and viceversa.
> 
> How to do this with GetOptions? Please help me.

The logic you want is unusual and will not be supported by Getopt::Long. I
believe you have two choices: 1) change the logic, 2) do the processing
yourself.

1. For more normal processing, combine the two options '-mod1_num -preserve'
into one (e.g., '-mod1_num_preserve') followed by the numerical argument.
This follows the normal logic supported by Getopt::Long.

2. If you can't change the logic, then process the command-line arguments
yourself with something like this (untested):

for( my $i = 0; $i < @ARGV; $i++ ) {
  if( $ARGV[$i] eq '-mod1_num' ) {
if( $ARGV[$i+1] eq '-preserve ) {
  $num = $ARGV[$i+2];
  $i += 2;
}else{
  $num = $ARGV[++$i];
}
  }elsif( $ARGV[$i] eq '-mod2_num' ) {
   ...
  }
}




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Getopt::Long in perl

2010-07-29 Thread Sooraj S
Hi,

I am using Getopt::Long to accept the command line arguments.

Logic
-
I have two mandatory options.
1.mod1_num
2.mod2_num

Both of them can accept either a 3digit number or another parameter
"preserve" which inturn accepts a 3digit number.

eg: my_script -mod1_num 123 -mod2_num 234
  my_script -mod1_num -preserve 123 mod2_num 234

If "preserve" is used with "mod1_num" it cannot be used with
"mod2_num" and viceversa.

How to do this with GetOptions? Please help me.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: getopt::long

2010-07-06 Thread Octavian Rasnita

Hi,

use strict;
use warnings;
use Getopt::Long;

my %hash;
GetOptions(\%hash, "first=s", "second|s=s", "third=i");

print $hash{first}, $hash{second}, $hash{third}, "\n";

--
Octavian

- Original Message - 
From: "Unknown User" 

To: "beginners" 
Sent: Tuesday, July 06, 2010 7:49 AM
Subject: getopt::long



um,

I am pretty sure getopt::long keeps all input data in a hash, does
anybody know whether i can use that hash itself in my code, and if so,
how?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



__ Information from ESET NOD32 Antivirus, version of virus 
signature database 5254 (20100706) __


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com






__ Information from ESET NOD32 Antivirus, version of virus signature 
database 5254 (20100706) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




getopt::long

2010-07-06 Thread Unknown User
um,

I am pretty sure getopt::long keeps all input data in a hash, does
anybody know whether i can use that hash itself in my code, and if so,
how?

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getopt::Long

2010-06-17 Thread Robert Wohlfarth
On Thu, Jun 17, 2010 at 6:50 AM, Shawn H Corey wrote:

> On 10-06-17 02:36 AM, Unknown User wrote:
>
>> I have the following code:
>>
>> GetOptions(
>>"n|name=s" =>   \$name,
>>"a|age=i" =>  \$age,
>>"s|sex=s" =>  \$sex,
>> ) || die "Bad options\n";;
>>
>
> But they are complete.  'name' is placed in $name, '-a' is placed in $sex,
> and @ARGV is left with ( '20' ).
>

Technically, -s does have a value: -a. GetOptions is treating "-a" as the
value for "-s" because the string "-a" immediately follows the option -s.
You could add validation on the value of "-s". For example...

GetOptions(
   "n|name=s" =>   \$name,
   "a|age=i" =>  \$age,
   "s|sex=s" =>  \$sex,
) || die "Bad options\n";;

if ($sex !~ m/m(ale)?|f(emale)?/i) { die "Invalid gender $sex\n"; }

-- 
Robert Wohlfarth


Re: Getopt::Long

2010-06-17 Thread Chas. Owens
On Thu, Jun 17, 2010 at 07:50, Shawn H Corey  wrote:
> On 10-06-17 02:36 AM, Unknown User wrote:
>>
>> I have the following code:
>>
>> GetOptions(
>>        "n|name=s" =>   \$name,
>>        "a|age=i" =>  \$age,
>>        "s|sex=s" =>  \$sex,
>> ) || die "Bad options\n";;
>
> GetOptions(
>        "name=s" =>     \$name,
>        "age=i" => \$age,
>        "sex=s" => \$sex,
> ) || die "Bad options\n";
>
> # GetOptions automatic determines which option by
> # the minimum leading letters needed to
> # distinguish them.
>
>>
>> What i expected this code to do is to die if a bad option was given,
>> say -s without an arguement, as in ./myprog -n name -s -a 20
>> However, it does not do that.
>>
>> What would be the correct method to die if one of the options is not
>> complete?
>>
>
> But they are complete.  'name' is placed in $name, '-a' is placed in $sex,
> and @ARGV is left with ( '20' ).
snip

Good point, try this:

#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Long;

#to test, run with no args
unless (@ARGV) {
for my $args (
[ qw/-n name -a 5 -s M/ ],
[ qw/-n -a 5 -s M/  ],
[ qw/-n name -a a -s M/ ],
[ qw/-n name -a -s M/   ],
[ qw/-n name -a 5 -s W/ ],
[ qw/-n name/   ],
) {
print "$0 @$args\n";
system $^X, $0, @$args;
print "-" x 5, "\n\n";
}

print "$0\n";
}

GetOptions(
"n|name=s" => \(my $name = "DEFAULT"),
"a|age=n"  => \(my $age  = "DEFAULT"),
"s|sex=s"  => \(my $sex  = "DEFAULT"),
) or die "bad options\n";

my $errfmt = qq{Value "%s" invalid for option "%s" (%s)\n};

die sprintf $errfmt, $sex, "-s", "M or F expected"
if length $sex and $sex =~ /^[^MF]$/;

die sprintf $errfmt, $name, "-n", "first character can't be a hyphen"
if length $name and $name =~ /^-/;

print "[$name] [$age] [$sex] @ARGV\n";



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

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getopt::Long

2010-06-17 Thread Shawn H Corey

On 10-06-17 02:36 AM, Unknown User wrote:

I have the following code:

GetOptions(
"n|name=s" =>  \$name,
"a|age=i" =>  \$age,
"s|sex=s" =>  \$sex,
) || die "Bad options\n";;


GetOptions(
"name=s" =>\$name,
"age=i" => \$age,
"sex=s" => \$sex,
) || die "Bad options\n";

# GetOptions automatic determines which option by
# the minimum leading letters needed to
# distinguish them.



What i expected this code to do is to die if a bad option was given,
say -s without an arguement, as in ./myprog -n name -s -a 20
However, it does not do that.

What would be the correct method to die if one of the options is not complete?



But they are complete.  'name' is placed in $name, '-a' is placed in 
$sex, and @ARGV is left with ( '20' ).



--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getopt::Long

2010-06-17 Thread Chas. Owens
On Thu, Jun 17, 2010 at 02:36, Unknown User  wrote:
> I have the following code:
>
> GetOptions(
>        "n|name=s" =>   \$name,
>        "a|age=i" => \$age,
>        "s|sex=s" => \$sex,
> ) || die "Bad options\n";;
>
> What i expected this code to do is to die if a bad option was given,
> say -s without an arguement, as in ./myprog -n name -s -a 20
> However, it does not do that.
>
> What would be the correct method to die if one of the options is not complete?


GetOptions should print a warning and return a false value in that
case.  What version of Perl and Getopt::Long are you using?  Try
running the following code.  If it does not die, then there is a
problem outside of your code.

#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Long;

for my $args ([qw/-n a/], ["-n"]) {
@ARGV = @$args;
GetOptions(
"n|name=s" => \my $name,
"a|age=s"  => \my $age,
"s|sex=s"  => \my $sex
) or die "bad options\n";
print "[$name] @ARGV\n";
}



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

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Getopt::Long

2010-06-16 Thread Unknown User
I have the following code:

GetOptions(
"n|name=s" =>   \$name,
"a|age=i" => \$age,
"s|sex=s" => \$sex,
) || die "Bad options\n";;

What i expected this code to do is to die if a bad option was given,
say -s without an arguement, as in ./myprog -n name -s -a 20
However, it does not do that.

What would be the correct method to die if one of the options is not complete?

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getopt::Long and Log::StdLog problem

2008-08-05 Thread rafailowski

Mr. Shawn H. Corey wrote:

On Tue, 2008-08-05 at 08:57 +0200, rafailowski wrote:
  
Thx but adding __END__ return me this error, anyway the problem is solve 
with a BEGIN block (cf.Rob Dixon).


$ perl test.pl --log-level=debug
Name "main::STDLOG" used only once: possible typo at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 51


Thx again.
rafailow.




Adding __END__ will not create this warning.  It is because no other
statement has STDLOG in it.  When you use it, this warning shall go
away.  Example:

  print {*STDLOG} info "printing to STDLOG\n";

  

Yes you're right, it' works fine now.
Thx for your help.

rafailow.

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




Re: Getopt::Long and Log::StdLog problem

2008-08-05 Thread Mr. Shawn H. Corey
On Tue, 2008-08-05 at 08:57 +0200, rafailowski wrote:
> Thx but adding __END__ return me this error, anyway the problem is solve 
> with a BEGIN block (cf.Rob Dixon).
> 
> $ perl test.pl --log-level=debug
> Name "main::STDLOG" used only once: possible typo at 
> /usr/local/share/perl/5.10.0/Log/StdLog.pm line 51
> 
> Thx again.
> rafailow.
> 

Adding __END__ will not create this warning.  It is because no other
statement has STDLOG in it.  When you use it, this warning shall go
away.  Example:

  print {*STDLOG} info "printing to STDLOG\n";


-- 
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster


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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread rafailowski

Mr. Shawn H. Corey wrote:

On Mon, 2008-08-04 at 20:47 -0400, Mr. Shawn H. Corey wrote:
  

On Tue, 2008-08-05 at 01:33 +0200, rafailowski wrote:


Yes, without argument, the error is normal :

$ perl test.pl
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.

Use of uninitialized value in string at test.pl line 25.

But with an argument like this :

$ perl test.pl --log-level=info
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.

info

level => $cmd_args_ref->{"log_level"} stay undef and
print $cmd_args_ref->{"log_level"}; return the good value.

I don't understand why in : use Log::StdLog {...}, the value of 
$cmd_args_ref->{"log_level"} stay always undef???



  

Sorry, I was thinking about the problem correctly.  Try:

#!/usr/bin/perl
use Getopt::Long;
use Log::StdLog;

my %cmd_args = ();
my $cmd_args_ref = \%cmd_args;

GetOptions(
"log-level=s"   =>  \$cmd_args{"log_level"},
);

sub log_format {
my ($date, $pid, $level, @message) = @_;
return "[$date][$level]: " . join(q{}, @message);
};

Log::Stdlog::import( {
format => \&log_format,
file => "$0.log",
level => $cmd_args_ref->{"log_level"},
} );



Oops, try this instead:

Log::Stdlog::import {
format => \&log_format,
file => "$0.log",
level => $cmd_args_ref->{"log_level"},
};


  

print $cmd_args_ref->{"log_level"};

__END__

This re-runs the import function after the program has started.

--
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster



Thx but adding __END__ return me this error, anyway the problem is solve 
with a BEGIN block (cf.Rob Dixon).


$ perl test.pl --log-level=debug
Name "main::STDLOG" used only once: possible typo at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 51


Thx again.
rafailow.

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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread rafailowski

Rob Dixon wrote:

rafailowski wrote:
  

I have a problem with Getopt::Long and Log::StdLog.

An example script, i always have the following error :
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57


level => $cmd_args_ref->{"log_level"} is always undef(???) but
print $cmd_args_ref->{"log_level"}; return the good value

I try to fix this with BEGIN block (around GetOptions) with no success

Is there a way to solve this (BEGIN INIT block?)

#!/usr/bin/perl

use warnings;
use strict;
use Getopt::Long;

my %cmd_args = ();
my $cmd_args_ref = \%cmd_args;

GetOptions(
"log-level=s"   =>  \$cmd_args{"log_level"},
);

sub log_format {
my ($date, $pid, $level, @message) = @_;
return "[$date][$level]: " . join(q{}, @message);
};

use Log::StdLog {
format => \&log_format,
file => "$0.log",
level => $cmd_args_ref->{"log_level"},
};

print $cmd_args_ref->{"log_level"};



Calling GetOptions in a BEGIN block will work fine, but the initialisation of
$cmd_args_ref must be done at the same time, otherwise it won't be set up when
Log::StdLog comes to be imported. The code below should do what you want.

HTH,

Rob



use strict;
use warnings;

use Getopt::Long;

my (%cmd_args, $cmd_args_ref);

BEGIN {
  GetOptions(
'log-level=s' => \$cmd_args{log_level},
  );
  $cmd_args_ref = \%cmd_args;
}

sub log_format {
  my ($date, $pid, $level, @message) = @_;
  local $" = q{};
  return "[$date][$level]: @message";
}

use Log::StdLog {
  format => \&log_format,
  file => "$0.log",
  level => $cmd_args_ref->{log_level},
};

print STDLOG user => "HELLO\n";
  

Ohhh, it works fine!
thanks for your help...
rafailow

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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread Mr. Shawn H. Corey
On Mon, 2008-08-04 at 20:47 -0400, Mr. Shawn H. Corey wrote:
> On Tue, 2008-08-05 at 01:33 +0200, rafailowski wrote:
> > Yes, without argument, the error is normal :
> > 
> > $ perl test.pl
> > Use of uninitialized value in hash element at 
> > /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.
> > Use of uninitialized value in string at test.pl line 25.
> > 
> > But with an argument like this :
> > 
> > $ perl test.pl --log-level=info
> > Use of uninitialized value in hash element at 
> > /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.
> > info
> > 
> > level => $cmd_args_ref->{"log_level"} stay undef and
> > print $cmd_args_ref->{"log_level"}; return the good value.
> > 
> > I don't understand why in : use Log::StdLog {...}, the value of 
> > $cmd_args_ref->{"log_level"} stay always undef???
> > 
> > 
> 
> Sorry, I was thinking about the problem correctly.  Try:
> 
> #!/usr/bin/perl
> use Getopt::Long;
> use Log::StdLog;
> 
> my %cmd_args = ();
> my $cmd_args_ref = \%cmd_args;
> 
> GetOptions(
> "log-level=s"   =>  \$cmd_args{"log_level"},
> );
> 
> sub log_format {
> my ($date, $pid, $level, @message) = @_;
> return "[$date][$level]: " . join(q{}, @message);
> };
> 
> Log::Stdlog::import( {
> format => \&log_format,
> file => "$0.log",
> level => $cmd_args_ref->{"log_level"},
> } );

Oops, try this instead:

Log::Stdlog::import {
format => \&log_format,
file => "$0.log",
level => $cmd_args_ref->{"log_level"},
};


> 
> print $cmd_args_ref->{"log_level"};
> 
> __END__
> 
> This re-runs the import function after the program has started.
> 
> -- 
> Just my 0.0002 million dollars worth,
>   Shawn
> 
> "Where there's duct tape, there's hope."
> 
> "Perl is the duct tape of the Internet."
> Hassan Schroeder, Sun's first webmaster
> 
> 
-- 
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster


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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread Rob Dixon
rafailowski wrote:
> 
> I have a problem with Getopt::Long and Log::StdLog.
> 
> An example script, i always have the following error :
> Use of uninitialized value in hash element at 
> /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57
> 
> level => $cmd_args_ref->{"log_level"} is always undef(???) but
> print $cmd_args_ref->{"log_level"}; return the good value
> 
> I try to fix this with BEGIN block (around GetOptions) with no success
> 
> Is there a way to solve this (BEGIN INIT block?)
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use Getopt::Long;
> 
> my %cmd_args = ();
> my $cmd_args_ref = \%cmd_args;
> 
> GetOptions(
> "log-level=s"   =>  \$cmd_args{"log_level"},
> );
> 
> sub log_format {
> my ($date, $pid, $level, @message) = @_;
> return "[$date][$level]: " . join(q{}, @message);
> };
> 
> use Log::StdLog {
> format => \&log_format,
> file => "$0.log",
> level => $cmd_args_ref->{"log_level"},
> };
> 
> print $cmd_args_ref->{"log_level"};

Calling GetOptions in a BEGIN block will work fine, but the initialisation of
$cmd_args_ref must be done at the same time, otherwise it won't be set up when
Log::StdLog comes to be imported. The code below should do what you want.

HTH,

Rob



use strict;
use warnings;

use Getopt::Long;

my (%cmd_args, $cmd_args_ref);

BEGIN {
  GetOptions(
'log-level=s' => \$cmd_args{log_level},
  );
  $cmd_args_ref = \%cmd_args;
}

sub log_format {
  my ($date, $pid, $level, @message) = @_;
  local $" = q{};
  return "[$date][$level]: @message";
}

use Log::StdLog {
  format => \&log_format,
  file => "$0.log",
  level => $cmd_args_ref->{log_level},
};

print STDLOG user => "HELLO\n";

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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread Mr. Shawn H. Corey
On Tue, 2008-08-05 at 01:33 +0200, rafailowski wrote:
> Yes, without argument, the error is normal :
> 
> $ perl test.pl
> Use of uninitialized value in hash element at 
> /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.
> Use of uninitialized value in string at test.pl line 25.
> 
> But with an argument like this :
> 
> $ perl test.pl --log-level=info
> Use of uninitialized value in hash element at 
> /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.
> info
> 
> level => $cmd_args_ref->{"log_level"} stay undef and
> print $cmd_args_ref->{"log_level"}; return the good value.
> 
> I don't understand why in : use Log::StdLog {...}, the value of 
> $cmd_args_ref->{"log_level"} stay always undef???
> 
> 

Sorry, I was thinking about the problem correctly.  Try:

#!/usr/bin/perl
use Getopt::Long;
use Log::StdLog;

my %cmd_args = ();
my $cmd_args_ref = \%cmd_args;

GetOptions(
"log-level=s"   =>  \$cmd_args{"log_level"},
);

sub log_format {
my ($date, $pid, $level, @message) = @_;
return "[$date][$level]: " . join(q{}, @message);
};

Log::Stdlog::import( {
format => \&log_format,
file => "$0.log",
level => $cmd_args_ref->{"log_level"},
} );

print $cmd_args_ref->{"log_level"};

__END__

This re-runs the import function after the program has started.

-- 
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster


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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread rafailowski

Mr. Shawn H. Corey wrote:

On Tue, 2008-08-05 at 01:05 +0200, rafailowski wrote:
  

Hi all,

I have a problem with Getopt::Long and Log::StdLog.

An example script, i always have the following error :
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57


level => $cmd_args_ref->{"log_level"} is always undef(???) but
print $cmd_args_ref->{"log_level"}; return the good value



$cmd_args_ref->{"log_level"} is undef unless you set with a command-line
argument.

  

I try to fix this with BEGIN block (around GetOptions) with no success

Is there a way to solve this (BEGIN INIT block?)

#!/usr/bin/perl

use warnings;
use strict;
use Getopt::Long;

my %cmd_args = ();
my $cmd_args_ref = \%cmd_args;

GetOptions(
"log-level=s"   =>  \$cmd_args{"log_level"},
);

sub log_format {
my ($date, $pid, $level, @message) = @_;
return "[$date][$level]: " . join(q{}, @message);
};

use Log::StdLog {
format => \&log_format,
file => "$0.log",
level => $cmd_args_ref->{"log_level"},



level => ( $cmd_args_ref->{"log_level"} || 'none' ),

  

};

print $cmd_args_ref->{"log_level"};

Thx in advance,
rafailow.



Yes, without argument, the error is normal :

$ perl test.pl
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.

Use of uninitialized value in string at test.pl line 25.

But with an argument like this :

$ perl test.pl --log-level=info
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.

info

level => $cmd_args_ref->{"log_level"} stay undef and
print $cmd_args_ref->{"log_level"}; return the good value.

I don't understand why in : use Log::StdLog {...}, the value of 
$cmd_args_ref->{"log_level"} stay always undef???



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




Re: Getopt::Long and Log::StdLog problem

2008-08-04 Thread Mr. Shawn H. Corey
On Tue, 2008-08-05 at 01:05 +0200, rafailowski wrote:
> Hi all,
> 
> I have a problem with Getopt::Long and Log::StdLog.
> 
> An example script, i always have the following error :
> Use of uninitialized value in hash element at 
> /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57
> 
> level => $cmd_args_ref->{"log_level"} is always undef(???) but
> print $cmd_args_ref->{"log_level"}; return the good value

$cmd_args_ref->{"log_level"} is undef unless you set with a command-line
argument.

> 
> I try to fix this with BEGIN block (around GetOptions) with no success
> 
> Is there a way to solve this (BEGIN INIT block?)
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use Getopt::Long;
> 
> my %cmd_args = ();
> my $cmd_args_ref = \%cmd_args;
> 
> GetOptions(
> "log-level=s"   =>  \$cmd_args{"log_level"},
> );
> 
> sub log_format {
> my ($date, $pid, $level, @message) = @_;
> return "[$date][$level]: " . join(q{}, @message);
> };
> 
> use Log::StdLog {
> format => \&log_format,
> file => "$0.log",
> level => $cmd_args_ref->{"log_level"},

level => ( $cmd_args_ref->{"log_level"} || 'none' ),

> };
> 
> print $cmd_args_ref->{"log_level"};
> 
> Thx in advance,
> rafailow.
> 
-- 
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster


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




Getopt::Long and Log::StdLog problem

2008-08-04 Thread rafailowski

Hi all,

I have a problem with Getopt::Long and Log::StdLog.

An example script, i always have the following error :
Use of uninitialized value in hash element at 
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57


level => $cmd_args_ref->{"log_level"} is always undef(???) but
print $cmd_args_ref->{"log_level"}; return the good value

I try to fix this with BEGIN block (around GetOptions) with no success

Is there a way to solve this (BEGIN INIT block?)

#!/usr/bin/perl

use warnings;
use strict;
use Getopt::Long;

my %cmd_args = ();
my $cmd_args_ref = \%cmd_args;

GetOptions(
   "log-level=s"   =>  \$cmd_args{"log_level"},
);

sub log_format {
   my ($date, $pid, $level, @message) = @_;
   return "[$date][$level]: " . join(q{}, @message);
};

use Log::StdLog {
   format => \&log_format,
   file => "$0.log",
   level => $cmd_args_ref->{"log_level"},
};

print $cmd_args_ref->{"log_level"};

Thx in advance,
rafailow.

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread John W. Krahn
Chas Owens wrote:

> On 6/3/07, Chas Owens <[EMAIL PROTECTED]> wrote:
>> On 6/3/07, Chas Owens <[EMAIL PROTECTED]> wrote:
>> snip
>> > my $tidy = "/usr/bin/tidy";
>> > my @tidy_args = qw(--foo --bar -- example);
>> > my $path = get_path();
>> > my $file = $path . get_file();
>> >
>> > system($tidy, @tidy_args, $file);
>>
>> Opps, forgot the error checking.
>>
>> system($tidy, @tidy_args, $file)
>> or die qq("$tidy @tidy_args $file" failed: $?";
>>
> 
> I will get it right, I swear.
> 
> system($tidy, @tidy_args, $file)
> or die qq("$tidy @tidy_args $file" failed: $?);

This should work better:

system($tidy, @tidy_args, $file) == 0
or die qq("$tidy @tidy_args $file" failed: $?);

Or:

system($tidy, @tidy_args, $file)
and die qq("$tidy @tidy_args $file" failed: $?);



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Mike Lesser

Okay, I eliminated the tidy with some more robust regex. D'oh!

Case closed!

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Chas Owens

On 6/3/07, Chas Owens <[EMAIL PROTECTED]> wrote:

On 6/3/07, Chas Owens <[EMAIL PROTECTED]> wrote:
snip
> my $tidy = "/usr/bin/tidy";
> my @tidy_args = qw(--foo --bar -- example);
> my $path = get_path();
> my $file = $path . get_file();
>
> system($tidy, @tidy_args, $file);

Opps, forgot the error checking.

system($tidy, @tidy_args, $file)
or die qq("$tidy @tidy_args $file" failed: $?";



I will get it right, I swear.

system($tidy, @tidy_args, $file)
   or die qq("$tidy @tidy_args $file" failed: $?);

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Chas Owens

On 6/3/07, Chas Owens <[EMAIL PROTECTED]> wrote:
snip

my $tidy = "/usr/bin/tidy";
my @tidy_args = qw(--foo --bar -- example);
my $path = get_path();
my $file = $path . get_file();

system($tidy, @tidy_args, $file);


Opps, forgot the error checking.

system($tidy, @tidy_args, $file)
   or die qq("$tidy @tidy_args $file" failed: $?";

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Chas Owens

On 6/3/07, Mike Lesser <[EMAIL PROTECTED]> wrote:
snip

Then I attempted to use Tidy, sans HTML::Tidy, through Shell. The
HTML::Tidy lib won't work on my system. So, I have been futzing with
tidy and I'v e discovered that tidy and simple commands like cd fail,
most likely because of the spaces in my paths.

For example, here's the path I pass to the script (no quotes):
 /Users/mike/Airline\ Sheets/Original\ Schedules/UnitedJune.html

Here's the path as found via File::Basename/fileparse:
 /Users/mike/Projects/Omni/Airline Sheets/Original Schedules/

snip

What you want is

my $tidy = "/usr/bin/tidy";
my @tidy_args = qw(--foo --bar -- example);
my $path = get_path();
my $file = $path . get_file();

system($tidy, @tidy_args, $file);

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Mike Lesser


On Jun 3, 2007, at 1:59 PM, Chas Owens wrote:


On 6/3/07, Mike Lesser <[EMAIL PROTECTED]> wrote:
snip

I have to assume that paths can be converted easily for use in shells
and such, without resorting to RegEx. Any ideas?

snip

Aside from the multi argument version of system that Tom has already
mentioned, the bigger question is "Why are you running code outside of
Perl?"  Often people think they need to say things like

system "rm -rf $path";
system "mkdir $path";
system "chmod 666 $path";



My intent is to keep it within Perl, but I seem to be going further  
outside of it due to this problem. I'm involved in all sorts of Perl- 
unrelated nonsense.


I've taken another look at HTML::Tidy, and it appears that there are  
some critical issues with the version of tidylib that's on Mac OS X,  
including the version number. Tidy's included, which is nice, but  
fink is intent on keeping the same (old) version.


I figure, get the latest from CVS, but there's been some problems  
there (probably due to me having never used it before). Rebuilding a  
new version of the lib hasn't been successful yet due to a variety of  
problems (but I may solve them tonite). Thus writing an Xsub to it  
(another thing for me to learn) seems excessive. Now I'm really far out!


Roadblocks everywhere!

I'm thinking that a little RegEx might just serve me better even  
though it's reinventing the wheel. This script is intended for use  
with a file from a specific vendor, which has it's own quirks (it  
looks like someone set it an exporter 10 years ago and then left the  
company) that make no sense. It's not _so_ bad to make some custom  
code, is it? Yuck.





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




Fwd: Paths, Spaces, Getopt::Long

2007-06-03 Thread Mike Lesser



Begin forwarded message:

From: Mike Lesser <[EMAIL PROTECTED]>
Date: June 3, 2007 3:48:56 PM EDT
To: "Chas Owens" <[EMAIL PROTECTED]>
Subject: Re: Paths, Spaces, Getopt::Long

On Jun 3, 2007, at 1:59 PM, Chas Owens wrote:


On 6/3/07, Mike Lesser <[EMAIL PROTECTED]> wrote:
snip

I have to assume that paths can be converted easily for use in shells
and such, without resorting to RegEx. Any ideas?

snip

Aside from the multi argument version of system that Tom has already
mentioned, the bigger question is "Why are you running code outside of
Perl?"  Often people think they need to say things like



The script needs to use tidy to strip garbage from an html file prior  
to reading it. It's a file automatically generated by another company  
and it's filled with junk, hence no chance to fix it at the source.


The HTML::Tidy module would be fine but it doesn't pass testing on my  
box, and won't work with a forced install. I took a look and found  
that that seems to be a recurring problem on OS X 10.4. I haven't yet  
looked thru the code to determine the source of the problem as it  
seemed that running either Shell or system () was an interesting  
thing to learn. I might have been wrong there!


I've had success running hard coded paths and stuff, but now see that  
there's this space problem, which I didn't realize since Perl was  
handling paths nicely all by itself!




system "rm -rf $path";
system "mkdir $path";
system "chmod 666 $path";

when they could just as easily say

use File::Path;
use File::chmod;

rmtree $path;
mkpath $path;
chmod 0666, $path;




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




Fwd: Paths, Spaces, Getopt::Long

2007-06-03 Thread Mike Lesser


Well I'm not sure. I may be explaining this badly. I'll go thru all  
the details in case it helps.


The path I pass when I'm executing the script is escaped, which I  
assume is correct.


Once that path is read by Getopt, I print it and, voila, no escapes,  
just nice-to-read spaces.


This path gets a filename appended as if it were a regular string,  
and is used to when I make a file (via another module). This file is  
created & written just fine. This made me assume all was well, and  
that Perl or the modules covered all the issues with spaces. I now  
realize this may have been naive.


Then I attempted to use Tidy, sans HTML::Tidy, through Shell. The  
HTML::Tidy lib won't work on my system. So, I have been futzing with  
tidy and I'v e discovered that tidy and simple commands like cd fail,  
most likely because of the spaces in my paths.


For example, here's the path I pass to the script (no quotes):
/Users/mike/Airline\ Sheets/Original\ Schedules/UnitedJune.html

Here's the path as found via File::Basename/fileparse:
/Users/mike/Projects/Omni/Airline Sheets/Original Schedules/

My script uses modules that create files based on this path, and it  
seems okay. If however I try to  use the path with say,  
the Shell mod, it fails. This is what cd returns:


/Users/mike/Projects/Omni/Airline: No such file or directory
.
I need to use the Shell because I need to run tidy, locally.


I fear that you're using the Shell module for more than it was
intended to do, perhaps because you don't know about system().



That may very well be the case!

One easy solution may be to give a list of arguments to system(). The
first is the name of the program you're trying to run, the rest of the
list are the command-line arguments to give it. You don't need to
escape anything, because the strings are passed as-is.

 # use the system's chmod command on a list of filenames
 system "chmod", "u+w", @filenames;

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training




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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Chas Owens

On 6/3/07, Mike Lesser <[EMAIL PROTECTED]> wrote:
snip

I have to assume that paths can be converted easily for use in shells
and such, without resorting to RegEx. Any ideas?

snip

Aside from the multi argument version of system that Tom has already
mentioned, the bigger question is "Why are you running code outside of
Perl?"  Often people think they need to say things like

system "rm -rf $path";
system "mkdir $path";
system "chmod 666 $path";

when they could just as easily say

use File::Path;
use File::chmod;

rmtree $path;
mkpath $path;
chmod 0666, $path;

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




Re: Paths, Spaces, Getopt::Long

2007-06-03 Thread Tom Phoenix

On 6/3/07, Mike Lesser <[EMAIL PROTECTED]> wrote:


I use the module Getopt::Long to read arguments, one of which is a
file path that may have spaces. The path string that is returned from
Getopt has spaces without escape chars.  The string seems to be fine
for Perl use, but not so great for other things, such as the Shell
module, which can't handle the spaces.


So, the problem isn't that Getopt::Long is giving you the correct file
name, which happens to contain spaces. The problem is that you're
passing a string containing shell metacharacters (spaces) to the
shell. Yes?

I fear that you're using the Shell module for more than it was
intended to do, perhaps because you don't know about system().

One easy solution may be to give a list of arguments to system(). The
first is the name of the program you're trying to run, the rest of the
list are the command-line arguments to give it. You don't need to
escape anything, because the strings are passed as-is.

 # use the system's chmod command on a list of filenames
 system "chmod", "u+w", @filenames;

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Paths, Spaces, Getopt::Long

2007-06-03 Thread Mike Lesser
Hi all. I have a problem that _must_ have a very simple solution  
(that I can't find).


I use the module Getopt::Long to read arguments, one of which is a  
file path that may have spaces. The path string that is returned from  
Getopt has spaces without escape chars.  The string seems to be fine  
for Perl use, but not so great for other things, such as the Shell  
module, which can't handle the spaces.


I have to assume that paths can be converted easily for use in shells  
and such, without resorting to RegEx. Any ideas?


Mike



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




Re: Getopt::Long

2005-11-08 Thread Bob Showalter

Chris Knipe wrote:

Hi all,
 
Just a quick question and a couple of lines of really simple code 
 
use Getopt::Long;
 
...
 
GetOptions ('h'   => \$h,

'b=s' => \$s );

Sub ShowHelp() {


That should be

  sub ShowHelp {

Perl isn't VB :)


  print "this is help"
}

Sub DoSomethingWithString() {
...
}

If ($s) {
  DoSomethingWithString();
} else {
  ShowHelp();
}
 
Right.  Now, whilst the above is not perhaps 100% correct, it goes about a

generality of Getopt::Long.

If I now run the application,
./blah.pl -h   - I get the help screen
./blah.pl -s   - I get a error, complaining that -s requires a value, and
THEN the help screen.
./blah.pl -s s - Everything is fine.

So, this is more of a block question I think, but how I can get the above
example to show the help screen FIRST, and THEN complain about the missing
value for -s 


Well, this is a little tricky, because the complaint is issued by the 
GetOptions() call. I would usually do something like:


   # just show the complaint
   GetOptions(...blah...) or exit 1;

or

   # show the complaint, then the help
   GetOptions(...blah...) or ShowHelp(), exit 1;

In order to show the help before the complaint, you need to "capture" 
the complaint with $SIG{__WARN__} something like this:


   my $msg = '';
   do {
   local $SIG{__WARN__} = sub { $msg .= shift };
   GetOptions('h'   => \$h, 'b=s' => \$s );
   } or ShowHelp(), die $msg;

I would suggest sending the help text to STDERR, or unbuffering STDOUT 
so that you are sure to get the help text shown before the complaint.


Also, you might look at Pod::Usage for an approach to handling the help 
text.


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




Re: Getopt::Long

2005-11-08 Thread Shawn Corey

Chris Knipe wrote:

So, this is more of a block question I think, but how I can get the above
example to show the help screen FIRST, and THEN complain about the missing
value for -s 


Why?

Here's an example of how to do it:

#!/usr/bin/perl

use strict;
use warnings;

use File::Basename;
use File::Copy 'copy';

my $TmpDir = '/tmp';  # Change to 'C:\TEMP' for MS DOS

my $Self = basename( $0 );
my $SaveOutFile = "$TmpDir/$Self.$$.out";
my $SaveErrFile = "$TmpDir/$Self.$$.err";

open SAVE_OUT, ">&STDOUT";
open SAVE_ERR, ">&STDERR";

my $umask = umask 0600;
open STDERR, "> $SaveErrFile";
open STDOUT, "> $SaveOutFile";
umask $umask;

my $string = '';
unless( GetOptions(
  'help'  => \&ShowHelp,
  'b=s'   => \$string,
)){
  open STDOUT, ">&SAVE_OUT";
  open STDERR, ">&SAVE_ERR";
  copy( $SaveErrFile, STDERR );
  copy( $SaveOutFile, STDOUT );
  ShowHelp;
}

if( $string ){
  open STDOUT, ">&SAVE_OUT";
  open STDERR, ">&SAVE_ERR";
  copy( $SaveErrFile, STDERR );
  copy( $SaveOutFile, STDOUT );

  # Place string munging here

}else{
  open STDOUT, ">&SAVE_OUT";
  open STDERR, ">&SAVE_ERR";
  ShowHelp;
  copy( $SaveErrFile, STDERR );
  copy( $SaveOutFile, STDOUT );
}

__END__


--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Getopt::Long

2005-11-07 Thread Timothy Johnson

An excerpt from the documentation:

"
  my $tag = '';   # option variable with default value
  GetOptions ('tag=s' => \$tag);

  In the option specification, the option name is followed by an equals
  sign "=" and the letter "s". The equals sign indicates that this
option
  requires a value. The letter "s" indicates that this value is an
  arbitrary string. Other possible value types are "i" for integer
  values..."







-Original Message-
From: Chris Knipe [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 07, 2005 7:38 PM
To: beginners@perl.org
Subject: Getopt::Long

Hi all,
 
Just a quick question and a couple of lines of really simple code 
 
use Getopt::Long;
 
...
 
GetOptions ('h'   => \$h,
'b=s' => \$s );

Sub ShowHelp() {
  print "this is help"
}

Sub DoSomethingWithString() {
...
}

If ($s) {
  DoSomethingWithString();
} else {
  ShowHelp();
}
 
Right.  Now, whilst the above is not perhaps 100% correct, it goes about
a
generality of Getopt::Long.

If I now run the application,
./blah.pl -h   - I get the help screen
./blah.pl -s   - I get a error, complaining that -s requires a value,
and
THEN the help screen.
./blah.pl -s s - Everything is fine.

So, this is more of a block question I think, but how I can get the
above
example to show the help screen FIRST, and THEN complain about the
missing
value for -s 

Thanks,
 
 
--
Regards,
Chris.
 


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




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




Getopt::Long

2005-11-07 Thread Chris Knipe
Hi all,
 
Just a quick question and a couple of lines of really simple code 
 
use Getopt::Long;
 
...
 
GetOptions ('h'   => \$h,
'b=s' => \$s );

Sub ShowHelp() {
  print "this is help"
}

Sub DoSomethingWithString() {
...
}

If ($s) {
  DoSomethingWithString();
} else {
  ShowHelp();
}
 
Right.  Now, whilst the above is not perhaps 100% correct, it goes about a
generality of Getopt::Long.

If I now run the application,
./blah.pl -h   - I get the help screen
./blah.pl -s   - I get a error, complaining that -s requires a value, and
THEN the help screen.
./blah.pl -s s - Everything is fine.

So, this is more of a block question I think, but how I can get the above
example to show the help screen FIRST, and THEN complain about the missing
value for -s 

Thanks,
 
 
--
Regards,
Chris.
 


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




Re: getopt long behaviour

2005-09-09 Thread Manish Sapariya

Oh, my understanding is that when I specify

"output=s"
its a mandatory parameter and if not specified on command line,
GetOptions should return error.

Am i missing something?
Thanks,
Manish



On 09/09/2005 05:56 PM, Chris Devers wrote:


On Fri, 9 Sep 2005, Manish Sapariya wrote:

 


Shouldn't following snippet throw error message when
it is called without any parameter?

I can't see any error messsage, why?
   



Because this didn't have an error. 

If you want it to quit, force it to quit. 


   #!/usr/bin/perl

   use Getopt::Long;
   GetOptions("verbose"  => \$verbose,
  "debug"=> \$debug,
  "output=s" => \$output) || print "No inputs specified\n";

   die "No output specified" unless defined $output;

   print "Executed successfully\n";



 




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




Re: getopt long behaviour

2005-09-09 Thread Jeff 'japhy' Pinyan

[PLEASE don't top-post; it makes it hard to follow the conversation]

On Sep 9, Manish Sapariya said:


On 09/09/2005 05:56 PM, Chris Devers wrote:


On Fri, 9 Sep 2005, Manish Sapariya wrote:


Shouldn't following snippet throw error message when
it is called without any parameter?


Because this didn't have an error. 
If you want it to quit, force it to quit.


die "No output specified" unless defined $output;


Oh, my understanding is that when I specify

"output=s"
its a mandatory parameter and if not specified on command line,
GetOptions should return error.

Am i missing something?


Yes.  What the documentation means is that the ARGUMENT to the parameter 
is mandatory, not the parameter itself.


  myprog --output

will cause an error, but

  myprog

and

  myprog --output=file

will not.


--
Jeff "japhy" Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: getopt long behaviour

2005-09-09 Thread Manish Sapariya

Oh, my understanding is that when I specify

"output=s"
its a mandatory parameter and if not specified on command line,
GetOptions should return error.

Am i missing something?
Thanks,
Manish


On 09/09/2005 05:56 PM, Chris Devers wrote:

On Fri, 9 Sep 2005, Manish Sapariya wrote:



Shouldn't following snippet throw error message when
it is called without any parameter?

I can't see any error messsage, why?



Because this didn't have an error. 

If you want it to quit, force it to quit. 
 
#!/usr/bin/perl
 
use Getopt::Long;

GetOptions("verbose"  => \$verbose,
   "debug"=> \$debug,
   "output=s" => \$output) || print "No inputs specified\n";

die "No output specified" unless defined $output;

print "Executed successfully\n";
 





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




Re: getopt long behaviour

2005-09-09 Thread Chris Devers
On Fri, 9 Sep 2005, Manish Sapariya wrote:

> Shouldn't following snippet throw error message when
> it is called without any parameter?
> 
> I can't see any error messsage, why?

Because this didn't have an error. 

If you want it to quit, force it to quit. 
 
    #!/usr/bin/perl
 
use Getopt::Long;
GetOptions("verbose"  => \$verbose,
   "debug"=> \$debug,
   "output=s" => \$output) || print "No inputs specified\n";

die "No output specified" unless defined $output;

print "Executed successfully\n";
 


-- 
Chris Devers

u+ûQ!Vév—Ø
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


getopt long behaviour

2005-09-09 Thread Manish Sapariya

Shouldn't following snippet throw error message when
it is called without any parameter?

I can't see any error messsage, why?


#  /tmp/test.pl
Executed successfully
#
--
#!/usr/bin/perl

use Getopt::Long;
GetOptions("verbose"  => \$verbose,
  "debug"=> \$debug,
  "output=s" => \$output) || print "No inputs specified\n";

print "Executed successfully\n";
---

Thanks,
Manish

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




Re: GetOpt::Long

2005-04-22 Thread John Doe
Hi Wim

> Hi Bob,
>
> You gave me the following answer earlier:
>
>sub foo {
>
>   local @ARGV = @_;
>   GetOptions(...blah...);
>
>   ...
>}
>
> If I run it as a seperate script, commenting out the (local @ARGV = @_;)
> line, then it works.  But it does not work when called as a subroutine from
> within the main script. 

Can you be more specific about "does not work" and "called ... from within the 
main script"?

Your code below is not a functional example, so I made some changes
(especially inserting "use strict" and "use warnings" which alway gives good 
hints :-), 
and it works - but maybe in the sense you mentioned that it works for you too:

=== begin script (test3.pl) ===
use strict; use warnings;
use Getopt::Long;

sub notify_email {
  local @ARGV = @_;

  my (@recipients, @subject, @body);
  my %conf=(smtp=>'whatever', smtpsender=>'something');

  $ENV{"NTsendmail"}  = $conf{'smtp'};
  my $sender = $conf{'smtpsender'};

  GetOptions ("r=s"  => [EMAIL PROTECTED],
  "s=s"  => [EMAIL PROTECTED],
  "b=s"  => [EMAIL PROTECTED]);
  my $subject= join(" ", @subject);
  my $body   = join(" ", @body);

  foreach my $recipient (@recipients) {
print "$sender, $recipient, $subject, $body\n";
#$mail = new NTsendmail;
#$mail->send($sender, $recipient, $subject, $body);
  }
}

notify_email (@ARGV);
=== end script ===

This prints:

something, , sss, 


> I have also tried (my @ARGV = @_;). 
> Any idea why?
>
> Here is my code now:
> =
> # Notify recipients via SMTP (email)
> # Usage: notify_email -r [EMAIL PROTECTED] -r [EMAIL PROTECTED] -s "Subject 
> line" -b
> "Message body"
> sub notify_email {
>   local @ARGV = @_;   # Get the sub's params into the master param array
> for GetOpt::Long
>   $ENV{"NTsendmail"}  = $conf{'smtp'};
>   $sender = $conf{'smtpsender'};
>
>   GetOptions ("r=s"  => [EMAIL PROTECTED],   # -r [EMAIL PROTECTED] -r 
> [EMAIL PROTECTED]
> -r [EMAIL PROTECTED]
>   "s=s"  => [EMAIL PROTECTED],  # -s "This is the subject
> line..."
>   "b=s"  => [EMAIL PROTECTED]);# -b "This is the 
> message
> body..."
>
>   $subject= join(" ", @subject);
>   $body   = join(" ", @body);
>
>   foreach $recipient (@recipients) {
> print "$sender, $recipient, $subject, $body\n";
> $mail = new NTsendmail;
> $mail->send($sender, $recipient, $subject, $body);
>   }
> }
> =
>
> ___
>___
>
> Standard Bank Disclaimer and Confidentiality Note
[...]


hth, joe

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




RE: GetOpt::Long

2005-04-21 Thread Olivier, Wim W
Hi Bob,

You gave me the following answer earlier:

   sub foo {

  local @ARGV = @_;
  GetOptions(...blah...);

  ...
   }

If I run it as a seperate script, commenting out the (local @ARGV = @_;)
line, then it works.  But it does not work when called as a subroutine from
within the main script. I have also tried (my @ARGV = @_;).
Any idea why?

Here is my code now:
=
# Notify recipients via SMTP (email)
# Usage: notify_email -r [EMAIL PROTECTED] -r [EMAIL PROTECTED] -s "Subject 
line" -b
"Message body"
sub notify_email {
  local @ARGV = @_;   # Get the sub's params into the master param array for
GetOpt::Long
  $ENV{"NTsendmail"}  = $conf{'smtp'};
  $sender = $conf{'smtpsender'};

  GetOptions ("r=s"  => [EMAIL PROTECTED],   # -r [EMAIL PROTECTED] -r 
[EMAIL PROTECTED]
-r [EMAIL PROTECTED]
  "s=s"  => [EMAIL PROTECTED],  # -s "This is the subject
line..."
  "b=s"  => [EMAIL PROTECTED]);# -b "This is the message
body..."

  $subject= join(" ", @subject);
  $body   = join(" ", @body);

  foreach $recipient (@recipients) {
print "$sender, $recipient, $subject, $body\n";
$mail = new NTsendmail;
$mail->send($sender, $recipient, $subject, $body);
  }
}
=

__

Standard Bank Disclaimer and Confidentiality Note

This e-mail, its attachments and any rights attaching hereto are, unless the 
context clearly indicates otherwise, the property of Standard Bank Group 
Limited and/or its subsidiaries ("the Group"). It is confidential, private and 
intended for the addressee only. 

Should you not be the addressee and receive this e-mail by mistake, kindly 
notify the sender, and delete this e-mail, immediately and do not disclose or 
use same in any manner whatsoever. 

Views and opinions expressed in this e-mail are those of the sender unless 
clearly stated as those of the Group. The Group accepts no liability whatsoever 
for any loss or damages whatsoever and howsoever incurred, or suffered, 
resulting, or arising, from the use of this email or its attachments.

The Group does not warrant the integrity of this e-mail nor that it is free of 
errors, viruses, interception or interference. 

Licensed divisions of the Standard Bank Group are authorised financial services 
providers in terms of the Financial Advisory and Intermediary Services Act, No 
37 of 2002 (FAIS).

For information about the Standard Bank Group Limited visit our website 
http://www.standardbank.co.za
___

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




RE: GetOpt::Long

2005-04-21 Thread Bob Showalter
Olivier, Wim W wrote:
> Hi Bob,

Hi. Don't top-post please.

> If 
> I comment out this if statement, I don't get the error anymore.  An
> clues as 
> to the correct syntax???
> 
> I run the subroutine as follows:
> 
> if ($conf{'pnl_check_for_analytics_email'} =~ 'ON')
>{ notify_email -r [EMAIL PROTECTED] -r
> [EMAIL PROTECTED] -s "Subject line" -b "Message body" };

You need to pass your arguments as a proper list, with commas and quotes:

notify_email('-r', '[EMAIL PROTECTED]',
'-r', '[EMAIL PROTECTED]', 
'-s', 'Subject Line',
'-b', 'Message Body');

You can omit the parens if notify_email has been declared above this code,
but I dont' recommend it.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: GetOpt::Long

2005-04-21 Thread Olivier, Wim W
Hi Bob,

(Offer Kaye, thanks for the reply as well!)

I used the method below (local @ARGV = @_;) to get the values of @_ into
@ARGV for the use of Getopt::Long.  It appears to be working fine like that.
I now have another problem with, it appears, syntax. The IF statement is
part of a block in the switch statement, but there is nothing wrong with the
switch statement itself, as there are many identical if statements there. If
I comment out this if statement, I don't get the error anymore.  An clues as
to the correct syntax???

I run the subroutine as follows:

if ($conf{'pnl_check_for_analytics_email'} =~ 'ON')
   { notify_email -r [EMAIL PROTECTED] -r
[EMAIL PROTECTED] -s "Subject line" -b "Message body" };


But I get the following error when it executes:

Bad switch statement (problem in the code block?)



Please see the code below:


==
# Notify recipients via SMTP (email)
# Usage: notify_email -r [EMAIL PROTECTED] -r [EMAIL PROTECTED] -s "Subject 
line" -b
"Message body"
sub notify_email {
  local @ARGV = @_;   # Get the sub's params into the master param array for
GetOpt::Long
  $ENV{"NTsendmail"}  = $conf{'smtp'};
  $sender = $conf{'smtpsender'};

  my @recipients;
  my @subject;
  my $body;
  GetOptions ("r=s"  => [EMAIL PROTECTED],   # -r [EMAIL PROTECTED] -r 
[EMAIL PROTECTED]
-r [EMAIL PROTECTED]
  "s=s"  => $subject,  # -s "This is the subject
line..."
  "b=s"  => $body);# -b "This is the message
body..."
  [EMAIL PROTECTED] = split(/,/,join(',',@recipients));
  #$subject= join(" ", @subject);
  #$body   = join(" ", @body);

  foreach $recipient (@recipients) {
print "$sender, $recipient, $subject, $body\n";
$mail = new NTsendmail;
$mail->send($sender, $recipient, $subject, $body);
  }

}
========
==

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: 20 April 2005 02:31 PM
To: Olivier, Wim W; Perl Beginners (E-mail)
Subject: RE: GetOpt::Long


Olivier, Wim W wrote:
> Hi all,
> 
> Is it possible to use GetOpt::Long (or something similar) in a
> subroutine 
> using @_ instead of in the standard way (using @ARGV)?


This should work:

   sub foo {

  local @ARGV = @_;
  GetOptions(...blah...);

  ...
   }

__

Standard Bank Disclaimer and Confidentiality Note

This e-mail, its attachments and any rights attaching hereto are, unless the 
context clearly indicates otherwise, the property of Standard Bank Group 
Limited and/or its subsidiaries ("the Group"). It is confidential, private and 
intended for the addressee only. 

Should you not be the addressee and receive this e-mail by mistake, kindly 
notify the sender, and delete this e-mail, immediately and do not disclose or 
use same in any manner whatsoever. 

Views and opinions expressed in this e-mail are those of the sender unless 
clearly stated as those of the Group. The Group accepts no liability whatsoever 
for any loss or damages whatsoever and howsoever incurred, or suffered, 
resulting, or arising, from the use of this email or its attachments.

The Group does not warrant the integrity of this e-mail nor that it is free of 
errors, viruses, interception or interference. 

Licensed divisions of the Standard Bank Group are authorised financial services 
providers in terms of the Financial Advisory and Intermediary Services Act, No 
37 of 2002 (FAIS).

For information about the Standard Bank Group Limited visit our website 
http://www.standardbank.co.za
___

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




Re: GetOpt::Long

2005-04-20 Thread Offer Kaye
On 4/20/05, Olivier, Wim W wrote:
> Hi all,
> 
> Is it possible to use GetOpt::Long (or something similar) in a subroutine

Getargs::Long - 
http://search.cpan.org/dist/Getargs-Long/

HTH,
-- 
Offer Kaye

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




RE: GetOpt::Long

2005-04-20 Thread Bob Showalter
Olivier, Wim W wrote:
> Hi all,
> 
> Is it possible to use GetOpt::Long (or something similar) in a
> subroutine 
> using @_ instead of in the standard way (using @ARGV)?


This should work:

   sub foo {

  local @ARGV = @_;
  GetOptions(...blah...);

  ...
   }

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




RE: GetOpt::Long

2005-04-20 Thread Tim Johnson


How about something like this?  It doesn't make it like GetOpt::Long,
but it does handle what you want.  Or you could just require that people
pass an array to your subroutine and save yourself a little work.  If
there is only one recipient, then it's a one-element array.

#

my $recipients = '[EMAIL PROTECTED]';
notify_email('[EMAIL PROTECTED]',$recipients,"test","this is my
body");
#my @recipients = qw([EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED]);
#notify_email('[EMAIL PROTECTED]',[EMAIL PROTECTED],"test","this is the
body");

sub notify_email{
   my ($sender,$rcpt,$subj,$body) = @_;
   my $recipient;
   if(ref($rcpt)){
   if(ref($rcpt) eq 'ARRAY'){
   $recipient = join(',',@{$rcpt});
   }elsif(ref($rcpt) eq 'SCALAR'){
   $recipient = ${$rcpt};
   }else{
   die "Invalid recipient parameter!\n";
   }
   }else{
   $recipient = $rcpt;
   }
   print $recipient."\n";
}

#

-Original Message-----
From: Olivier, Wim W [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 20, 2005 12:53 AM
To: Perl Beginners (E-mail)
Subject: GetOpt::Long

Hi all,

Is it possible to use GetOpt::Long (or something similar) in a
subroutine
using @_ instead of in the standard way (using @ARGV)?
I want to have the following scenario, but use GetOpt in a subrouting
within
the main script and pass options (and values) to the subroutine.
The values ($recipient, $subject, $body) must be configurable and they
must
be able to take multiple values, i.e. multiple recipients for a message.


# Notify recipients via SMTP (email)
sub notify_email {
  $ENV{"NTsendmail"}  = $smtp;
  $sender = "[EMAIL PROTECTED]";
  $recipient  = "[EMAIL PROTECTED]";
  $subject= "ALERT";
  $body   = join " ", @_;
  $mail   = new NTsendmail;
  $mail->send($sender, $recipient, $subject, $body);
}



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




GetOpt::Long

2005-04-20 Thread Olivier, Wim W
Hi all,

Is it possible to use GetOpt::Long (or something similar) in a subroutine
using @_ instead of in the standard way (using @ARGV)?
I want to have the following scenario, but use GetOpt in a subrouting within
the main script and pass options (and values) to the subroutine.
The values ($recipient, $subject, $body) must be configurable and they must
be able to take multiple values, i.e. multiple recipients for a message.


# Notify recipients via SMTP (email)
sub notify_email {
  $ENV{"NTsendmail"}  = $smtp;
  $sender = "[EMAIL PROTECTED]";
  $recipient  = "[EMAIL PROTECTED]";
  $subject= "ALERT";
  $body   = join " ", @_;
  $mail   = new NTsendmail;
  $mail->send($sender, $recipient, $subject, $body);
}


All help appreciated!  Thanks in advance.


Kind Regards,

Wim Olivier

__

Standard Bank Disclaimer and Confidentiality Note

This e-mail, its attachments and any rights attaching hereto are, unless the 
context clearly indicates otherwise, the property of Standard Bank Group 
Limited and/or its subsidiaries ("the Group"). It is confidential, private and 
intended for the addressee only. 

Should you not be the addressee and receive this e-mail by mistake, kindly 
notify the sender, and delete this e-mail, immediately and do not disclose or 
use same in any manner whatsoever. 

Views and opinions expressed in this e-mail are those of the sender unless 
clearly stated as those of the Group. The Group accepts no liability whatsoever 
for any loss or damages whatsoever and howsoever incurred, or suffered, 
resulting, or arising, from the use of this email or its attachments.

The Group does not warrant the integrity of this e-mail nor that it is free of 
errors, viruses, interception or interference. 

Licensed divisions of the Standard Bank Group are authorised financial services 
providers in terms of the Financial Advisory and Intermediary Services Act, No 
37 of 2002 (FAIS).

For information about the Standard Bank Group Limited visit our website 
http://www.standardbank.co.za
___

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




Re: need help for Getopt::Long; --resolved

2005-03-25 Thread Shiping Wang
At 10:46 AM 3/25/2005 -0600, Shiping Wang wrote:
Hi, I have problem to match array defined in Getopt::Long and transfer to 
new file:
If I do:
try.pl --InputData sample.txt --Trait=_BMI --covars=age, _DBP, _SBP 
--Race=Others
with this file:
GFAMID  GDADID  GMOMID  ID  SEX 
HYT3  _SBP  _DBP  _BMI  RACE  AGE   _HTMED  antiht

How can I get it to new file like this:
A   HYT3
C   _SBP
C   _DBP
T   _BMI
S   RACE
C   AGE
S   _HTMED
S   antiht
Thanks!!!
SW
###
#!/usr/local/bin/perl
# try.pl
use warnings;
use strict;
use Getopt::Long;
my $inputData =' ';
my $trait= ' ';
my $race;
my @covars;
my $result = GetOptions("InputData=s" => \$inputData,
"Trait=s" 
=> \$trait,
"Race=s" 
=> \$race,

"Covars=s" => [EMAIL PROTECTED]
);
my @covarlist = split(/,/, 
@covars);
if(!$inputData){
exit();
}
#die "you must specify all parameters\n\t--Trait --Race 
--Covars\n" unless(define $trait || define $race || define @covars);
my $oriname = (split/\./, $inputData)[0];
my $outname;
if ($race){
$outname = "$oriname\_$race";
} else{
$outname = "$oriname";
}

open (outDat, ">$outname.dat") or die $!;
open (inPed, "$inputData") or die $!;
my $header = ;
chomp $header;
my @headline = split/\t/, $header;
my @ped_n_trait = @headline[0, 3, 1, 2, 4..12];
my %vartype;
### not working
foreach my $i (@ped_n_trait[5..12]){
if ($i eq 'HYT3'){
$vartype{$i} = 'A';
}elsif ($i eq "$trait"){
$vartype{$i} = 'T';
}else{
$vartype{$i} = 'S';
for(@covarlist){
if($_ eq "$i"){
$vartype{$_} = 'C';
}
}
}
}
### working, maybe better way to it ###
foreach my $i (@ped_n_trait[5..12]){
if ($i eq 'HYT3'){
$vartype{$i} = 'A';
}elsif ($i eq "$trait"){
$vartype{$i} = 'T';
}else{
for(@covarlist){
  if($_ eq "$i"){
$vartype{$i} = 'C';
}
$vartype{$i} = 'S' if (!$vartype{$i});
}
}
}
for (@ped_n_trait[5..12]){
print outDat "$vartype{$_}\t$_\n";
}
close outDat;
close inPed;

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


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



need help for Getopt::Long;

2005-03-25 Thread Shiping Wang
Hi, I have problem to match array defined in Getopt::Long and transfer to 
new file:
If I do:
try.pl --InputData sample.txt --Trait=_BMI --covars=age, _DBP, _SBP 
--Race=Others
with this file:
GFAMID  GDADID  GMOMID  ID  SEX 
HYT3  _SBP  _DBP  _BMI  RACE  AGE	 _HTMED  antiht

How can I get it to new file like this:
A   HYT3
C   _SBP
C   _DBP
T   _BMI
S   RACE
C   AGE
S   _HTMED
S   antiht
Thanks!!!
SW
###
#!/usr/local/bin/perl
# try.pl
use warnings;
use strict;
use Getopt::Long;
		my $inputData =' ';
		my $trait= ' ';
		my $race;
		my @covars;
		my $result = GetOptions("InputData=s" => \$inputData,
"Trait=s" => \$trait,
"Race=s" => \$race,
"Covars=s" => [EMAIL PROTECTED]
);
		my @covarlist = split(/[\s|,]/, @covars);		
		if(!$inputData){
			exit();
		}
	#die "you must specify all parameters\n\t--Trait --Race --Covars\n" 
unless(define $trait || define $race || define @covars);
my $oriname = (split/\./, $inputData)[0];
my $outname;
if ($race){
	$outname = "$oriname\_$race";
} else{
	$outname = "$oriname";
}
		

open (outDat, ">$outname.dat") or die $!;
open (inPed, "$inputData") or die $!;
my $header = ;
chomp $header;
my @headline = split/\t/, $header;
my @ped_n_trait = @headline[0, 3, 1, 2, 4..12];
my %vartype;
foreach my $i (@ped_n_trait[5..12]){
if ($i eq 'HYT3'){
$vartype{$i} = 'A';
}elsif ($i eq "$trait"){
$vartype{$i} = 'T';
}else{
$vartype{$i} = 'S';
for(@covarlist){
if($_ eq "$i"){
$vartype{$_} = 'C';
}
}

}
}
for (@ped_n_trait[5..12]){
print outDat "$vartype{$_}\t$_\n";
}
close outDat;
close inPed;

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



Re: Getopt::Long , handles the number zero differently..

2004-12-21 Thread John W. Krahn
Mike Donnelly wrote:
 Using the example code below, I find that I can 
  use getopt handily to pass all sorts of 
  variables to my script, as long as a 
  value passed is not a 0 (zero) 
 
 How to I use getopt::long and be able to 
  pass the number zero as a value? 
  Code, and  behavior follows 
   
 .
 MYTEST
 #!/usr/local/bin/perl
 use Getopt::Long;
 GetOptions("o"=>\$oflag,
 "string=s"=>\$stringmandatory,
 "int=i"=> \$mandatoryinteger,
 print "oflag $oflag\n" if $oflag;
 print "stringmandatory $stringmandatory\n" if
 $stringmandatory;
 print "mandatoryinteger $mandatoryinteger\n" if
 $mandatoryinteger;
Change the previous three lines to:
 print "oflag $oflag\n" if defined $oflag;
 print "stringmandatory $stringmandatory\n" if defined $stringmandatory;
 print "mandatoryinteger $mandatoryinteger\n" if defined $mandatoryinteger;

 print "Unprocessed by Getopt::Long\n" if $ARGV[0];
Change that one to:
 print "Unprocessed by Getopt::Long\n" if @ARGV;
($ARGV[0] could also be "0"!)

 foreach (@ARGV) {
   print "$_\n";
 }

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



Getopt::Long , handles the number zero differently..

2004-12-21 Thread Mike Donnelly

Using the example code below, I find that I can 
 use getopt handily to pass all sorts of 
 variables to my script, as long as a 
 value passed is not a 0 (zero) 

How to I use getopt::long and be able to 
 pass the number zero as a value? 
 Code, and  behavior follows 
  
  Thanks! Mike D
.
MYTEST
#!/usr/local/bin/perl
use Getopt::Long;
GetOptions("o"=>\$oflag,
"string=s"=>\$stringmandatory,
"int=i"=> \$mandatoryinteger,
print "oflag $oflag\n" if $oflag;
print "stringmandatory $stringmandatory\n" if
$stringmandatory;
print "mandatoryinteger $mandatoryinteger\n" if
$mandatoryinteger;

print "Unprocessed by Getopt::Long\n" if $ARGV[0];
foreach (@ARGV) {
  print "$_\n";
}

# ./MYTEST -stringmandatory=1
Unknown option: stringmandatory
# ./MYTEST --stringmandatory=1
Unknown option: stringmandatory
# ./MYTEST --string
Option string requires an argument
# ./MYTEST --string
Option string requires an argument
# ./MYTEST --string=abc
stringmandatory abc
# ./MYTEST --string=1
stringmandatory 1
# ./MYTEST --string=0
# ./MYTEST --int=0
# ./MYTEST --int=1
mandatoryinteger 1


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




Re: Getopt::Long , handles the number zero differently..

2004-12-21 Thread Mike Donnelly

--- [EMAIL PROTECTED] wrote:
> 
> 
> - Original Message -
> From: Mike Donnelly <[EMAIL PROTECTED]>
> Date: Tuesday, December 21, 2004 10:58 am
> Subject: Getopt::Long , handles the number zero
> differently..
> 
> Hello
> > 
> > 
> > Using the example code below, I find that I can 
> 
> Please paste working code

Sorry Bout' that .. chopped a line 

> >  use getopt handily to pass all sorts of 
> >  variables to my script, as long as a 
> >  value passed is not a 0 (zero) 
> 
> are you sure ??

Well, I WAS sure.. 

> > 
> > How to I use getopt::long and be able to 
> >  pass the number zero as a value? 

> exactly as you coded below. The problem is not in
> your getopt code, but in your print statment. The OP
> if $foo, will return false on integer value of 0. 

You are correct and I thank you for the help.
 
> 
> >  Code, and  behavior follows 
> >       
> >   Thanks! Mike D
> > .
> > MYTEST
> > #!/usr/local/bin/perl
> > use Getopt::Long;
> > GetOptions("o"=>\$oflag,
> > "string=s"=>\$stringmandatory,
> > "int=i"=> \$mandatoryinteger,
> > print "oflag $oflag\n" if $oflag;
> > print "stringmandatory $stringmandatory\n" if
> > $stringmandatory;
> > print "mandatoryinteger $mandatoryinteger\n" if
> > $mandatoryinteger;
> # try this
>   print "mandatoryinteger $mandatoryinteger\n" if
> $mandatoryinteger >= 0;
> > 
> > print "Unprocessed by Getopt::Long\n" if $ARGV[0];
> > foreach (@ARGV) {
> >   print "$_\n";
> > }
> > 
> > 
> > # ./MYTEST --string=abc
> > stringmandatory abc
> > # ./MYTEST --string=1
> > stringmandatory 1
> > # ./MYTEST --string=0
> > # ./MYTEST --int=0
> > # ./MYTEST --int=1
> > mandatoryinteger 1
> 
> HTH,
> Mark G
> > 
> > 
> > 
> > 
> > 
> > 
> > __ 
> > Do you Yahoo!? 
> > The all-new My Yahoo! - Get yours free! 
> > http://my.yahoo.com 
> > 
> > 
> > 
> > -- 
> > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > For additional commands, e-mail:
> [EMAIL PROTECTED]
> > <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
> > 
> > 
> > 
> 
> 




__ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

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




Re: Getopt::Long , handles the number zero differently..

2004-12-21 Thread mgoland


- Original Message -
From: Mike Donnelly <[EMAIL PROTECTED]>
Date: Tuesday, December 21, 2004 10:58 am
Subject: Getopt::Long , handles the number zero differently..

Hello
> 
> 
> Using the example code below, I find that I can 

Please paste working code
>  use getopt handily to pass all sorts of 
>  variables to my script, as long as a 
>  value passed is not a 0 (zero) 

are you sure ??
> 
> How to I use getopt::long and be able to 
>  pass the number zero as a value? 
exactly as you coded below. The problem is not in your getopt code, but in your 
print statment. The OP if $foo, will return false on integer value of 0. 

>  Code, and  behavior follows 
>   
>   Thanks! Mike D
> .
> MYTEST
> #!/usr/local/bin/perl
> use Getopt::Long;
> GetOptions("o"=>\$oflag,
> "string=s"=>\$stringmandatory,
> "int=i"=> \$mandatoryinteger,
> print "oflag $oflag\n" if $oflag;
> print "stringmandatory $stringmandatory\n" if
> $stringmandatory;
> print "mandatoryinteger $mandatoryinteger\n" if
> $mandatoryinteger;
# try this
  print "mandatoryinteger $mandatoryinteger\n" if $mandatoryinteger >= 0;
> 
> print "Unprocessed by Getopt::Long\n" if $ARGV[0];
> foreach (@ARGV) {
>   print "$_\n";
> }
> 
> 
> # ./MYTEST --string=abc
> stringmandatory abc
> # ./MYTEST --string=1
> stringmandatory 1
> # ./MYTEST --string=0
> # ./MYTEST --int=0
> # ./MYTEST --int=1
> mandatoryinteger 1

HTH,
Mark G
> 
> 
> 
> 
> 
>   
> __ 
> Do you Yahoo!? 
> The all-new My Yahoo! - Get yours free! 
> http://my.yahoo.com 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


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




Getopt::Long , handles the number zero differently..

2004-12-21 Thread Mike Donnelly


 Using the example code below, I find that I can 
  use getopt handily to pass all sorts of 
  variables to my script, as long as a 
  value passed is not a 0 (zero) 
 
 How to I use getopt::long and be able to 
  pass the number zero as a value? 
  Code, and  behavior follows 
   
   Thanks! Mike D
 .
 MYTEST
 #!/usr/local/bin/perl
 use Getopt::Long;
 GetOptions("o"=>\$oflag,
 "string=s"=>\$stringmandatory,
 "int=i"=> \$mandatoryinteger,
 print "oflag $oflag\n" if $oflag;
 print "stringmandatory $stringmandatory\n" if
 $stringmandatory;
 print "mandatoryinteger $mandatoryinteger\n" if
 $mandatoryinteger;
 
 print "Unprocessed by Getopt::Long\n" if $ARGV[0];
 foreach (@ARGV) {
   print "$_\n";
 }
 

 # ./MYTEST --string=abc
 stringmandatory abc
 # ./MYTEST --string=1
 stringmandatory 1
 # ./MYTEST --string=0
 # ./MYTEST --int=0
 # ./MYTEST --int=1
 mandatoryinteger 1
 
 




__ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 


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




Re: Getopt::Std vs. Getopt::Long

2004-07-14 Thread Wiggins d Anconia
> I have been using Getopt::Std for some time and I'm pretty happy with it. 
> I've been reading about Getopt::Long and it seems to support everything in
> Getopt::Std and has some nice conveniences.  Does anyone have experience
> converting scripts (or just development process) from Std to Long?  Does
> anyone have pretty good code examples using Getopt::Long?
> 

I created a template for use with Getopt::Long a while ago and posted it
here, then put it on my site, as well as a quick ref for G::L.

Both can be had here:

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

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>




Getopt::Std vs. Getopt::Long

2004-07-14 Thread perl.org
I have been using Getopt::Std for some time and I'm pretty happy with it. 
I've been reading about Getopt::Long and it seems to support everything in
Getopt::Std and has some nice conveniences.  Does anyone have experience
converting scripts (or just development process) from Std to Long?  Does
anyone have pretty good code examples using Getopt::Long?

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




Re: Getopt::Long::Configure('auto_help')

2004-01-08 Thread Wiggins d Anconia


> 
> How do I take advantage of this? I turn it on but I do not know how to get
> it to display a help message. If I pass in -h --help it just ends. I am
> assuming I need some kind of pod file but I am unknowledgeable on how to
> write a pod file. Also how do I tell it what pod file to open?
> 
> Form perldoc Getopt::Long
> 
> Configuring Getopt::Long
> Getopt::Long can be configured by calling subroutine
> Getopt::Long::Configure(). This subroutine takes a list of quoted
> strings, each specifying a configuration option to be enabled, e.g.
> "ignore_case", or disabled, e.g. "no_ignore_case". Case does not
matter.
> Multiple calls to Configure() are possible.
> 
> auto_help (default:disabled)
> Automatically provide support for the --help and -?
options
> if the application did not specify a handler for this
option
> itself.
> 
> Getopt::Long will provide a help message using module
> Pod::Usage. The message, derived from the SYNOPSIS POD
> section, will be written to standard output and processing
> will terminate.
> 
> "auto_help" will be enabled if the calling program
> explicitly specified a version number higher than 2.32 in
> the "use" or "require" statement.
> 

The key is in the docs you posted, specifically, "will provide a help
message using module Pod::Usage", I would suggest you have a look at the
docs for that module it should clear things up nicely. Particularly have
a look at the section "Recommended Use" that should help even more. I
have had good luck combining the two, though was unaware that this could
be handled automagically for me, very cool, I usually just code it in to
catch --help and -h and call pod2usage explicitly, god Perl+CPAN rocks...

I posted a template that takes advantage of this strategy late last year
if you want to check the archives, or e-mail me off list and I will fire
you a copy

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>




Getopt::Long::Configure('auto_help')

2004-01-08 Thread Paul Kraus
How do I take advantage of this? I turn it on but I do not know how to get
it to display a help message. If I pass in -h --help it just ends. I am
assuming I need some kind of pod file but I am unknowledgeable on how to
write a pod file. Also how do I tell it what pod file to open?

Form perldoc Getopt::Long

Configuring Getopt::Long
Getopt::Long can be configured by calling subroutine
Getopt::Long::Configure(). This subroutine takes a list of quoted
strings, each specifying a configuration option to be enabled, e.g.
"ignore_case", or disabled, e.g. "no_ignore_case". Case does not matter.
Multiple calls to Configure() are possible.

auto_help (default:disabled)
Automatically provide support for the --help and -? options
if the application did not specify a handler for this option
itself.

    Getopt::Long will provide a help message using module
Pod::Usage. The message, derived from the SYNOPSIS POD
section, will be written to standard output and processing
will terminate.

"auto_help" will be enabled if the calling program
explicitly specified a version number higher than 2.32 in
the "use" or "require" statement.

TIA,

 Paul Kraus
 ---
 PEL Supply Company
 Network Administrator
 ---
 800 321-1264 Toll Free
 216 267-5775 Voice
 216 267-6176 Fax
 www.pelsupply.com
 ---


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


RE: Using GetOpt::Long

2002-09-19 Thread David Samuelsson (PAC)

ahh this was what i was looking for.

GetOptions(
reg_backup  =>  \®_backup,
html=>  \&html,
);

works like a charm! Thanks.

//Dave

-Original Message-
From: Michael Fowler [mailto:[EMAIL PROTECTED]]
Sent: den 19 september 2002 22:29
To: David Samuelsson (PAC)
Cc: [EMAIL PROTECTED]
Subject: Re: Using GetOpt::Long


On Thu, Sep 19, 2002 at 10:02:32AM +0200, David Samuelsson (PAC) wrote:
> I want it so it will execute the subs in the order according to the lines
> when i start the scrippt, and i will try to keep to default -value cause
> the scipt will probably be used by others aswell so no double --.

You don't want to make other people use the '--' switches to use the script? 
Why not?  Getopt::Long will probably accommodate you in this, but I would
suggest reserving the single '-' for one-letter options, and the double '-'
for long options.  That way, the one-letter options can be bundled, e.g. -rh
for --reg_backup and --html.

Also, it might be more natural to use 'reg-backup', instead of 'reg_backup'.


> when i run myscript.pl -reg_backup -html
> 
> it should execute reg_backup sub first then the html sub.

This can be accomplished by specifying a subroutine reference as your value,
instead of a scalar reference.  E.g.

GetOptions(
reg_backup  =>  \®_backup,
html=>  \&html,
);

You mentioned in a previous message in this thread that reg_backup would
setup an array, and html would process it.  This would have to be
accomplished by some shared variable; html() would have to verify the
variable was setup correctly, and if not, do something to notify the user.

See the "User-defined subroutines to handle options" section in perldoc
Getopt::Long.  I would suggest you read the entire perldoc for the module at
least once, to get an idea of what it provides.


> I plan to have an exit sub that will run if they havent put the switches
> togheter right. It will be more commnd lines, so if they enter it wrong it
> will die with an error. and off course there will be some command line
> that will run almost all subs, but in the order i have specified. So when
> they specify lets say -all switch it goes to $all here is an order off all
> subs and the order it should run them in..

I don't completely understand what you're trying to describe here. 
Hopefully the advice I've already given will give you enough of a starting
point to solve the problem yourself.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Using GetOpt::Long

2002-09-19 Thread Michael Fowler

On Thu, Sep 19, 2002 at 10:02:32AM +0200, David Samuelsson (PAC) wrote:
> I want it so it will execute the subs in the order according to the lines
> when i start the scrippt, and i will try to keep to default -value cause
> the scipt will probably be used by others aswell so no double --.

You don't want to make other people use the '--' switches to use the script? 
Why not?  Getopt::Long will probably accommodate you in this, but I would
suggest reserving the single '-' for one-letter options, and the double '-'
for long options.  That way, the one-letter options can be bundled, e.g. -rh
for --reg_backup and --html.

Also, it might be more natural to use 'reg-backup', instead of 'reg_backup'.


> when i run myscript.pl -reg_backup -html
> 
> it should execute reg_backup sub first then the html sub.

This can be accomplished by specifying a subroutine reference as your value,
instead of a scalar reference.  E.g.

GetOptions(
reg_backup  =>  \®_backup,
html=>  \&html,
);

You mentioned in a previous message in this thread that reg_backup would
setup an array, and html would process it.  This would have to be
accomplished by some shared variable; html() would have to verify the
variable was setup correctly, and if not, do something to notify the user.

See the "User-defined subroutines to handle options" section in perldoc
Getopt::Long.  I would suggest you read the entire perldoc for the module at
least once, to get an idea of what it provides.


> I plan to have an exit sub that will run if they havent put the switches
> togheter right. It will be more commnd lines, so if they enter it wrong it
> will die with an error. and off course there will be some command line
> that will run almost all subs, but in the order i have specified. So when
> they specify lets say -all switch it goes to $all here is an order off all
> subs and the order it should run them in..

I don't completely understand what you're trying to describe here. 
Hopefully the advice I've already given will give you enough of a starting
point to solve the problem yourself.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using GetOpt::Long

2002-09-19 Thread Jeff AA

> -Original Message-
> From: David Samuelsson (PAC) 
> [mailto:[EMAIL PROTECTED]] 
> Sent: 19 September 2002 09:03
> To: 'Jeff AA'; [EMAIL PROTECTED]
> Subject: RE: Using GetOpt::Long
> 
> 
> I want it so it will execute the subs in the order according 
> to the lines when i start the scrippt, and i will try to  
> keep to default -value cause the scipt will probably be used 
> by others aswell so no double --.
> 
> when i run myscript.pl -reg_backup -html
> 
> it should execute reg_backup sub first then the html sub. I 
> plan to have an exit sub that will run if they havent put the 
> switches togheter right. It will be more commnd lines, so if 
> they enter it wrong it will die with an error. and off course 
> there will be some command line that will run almost all 
> subs, but in the order i have specified. So when they specify 
> lets say -all switch it goes to $all here is an order off all 
> subs and the order it should run them in..
> 

in that case don't bother with GetOpts, as it doesn't maintain the order
of the parameters. Try something like this:

use strict;

# This is the default order when no params set
my @funcs = (qw( func1, func2, func3, func4 ));

# Parameters override the defaults
@funcs = @ARGV if @ARGV;

# map the parameter names to the addresses of the subs
my %despatch = (
  func1 => \&func1,
  func2 => \&func2,
  func3 => \&func3,
  func4 => \&func4,
);

# Do the funcky stuff in user determined order
my @result;
for my $func ( @funcs ) {
  $func = lc($func); # case-insensitive
  # Do we have a function that matches the user requested name?
  if ( $despatch{$func} ) {
@result = &{$despatch{$func}}( \@result ) 
  } else {
die "Unrecognised function: '$func'";
  } 
}

then just call 
  myscript.pl func2 func4 func1


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using GetOpt::Long

2002-09-19 Thread David Samuelsson (PAC)

I want it so it will execute the subs in the order according to the lines when i start 
the scrippt, and i will try to  keep to default -value cause the scipt will probably 
be used by others aswell so no double --.

when i run myscript.pl -reg_backup -html

it should execute reg_backup sub first then the html sub. I plan to have an exit sub 
that will run if they havent put the switches togheter right. It will be more commnd 
lines, so if they enter it wrong it will die with an error. and off course there will 
be some command line that will run almost all subs, but in the order i have specified. 
So when they specify lets say -all switch it goes to $all here is an order off all 
subs and the order it should run them in..

//Dave
-Original Message-
From: Jeff AA [mailto:[EMAIL PROTECTED]]
Sent: den 19 september 2002 09:39
To: 'David Samuelsson (PAC)'; [EMAIL PROTECTED]
Subject: RE: Using GetOpt::Long



> -Original Message-
> From: David Samuelsson (PAC) 
> [mailto:[EMAIL PROTECTED]] 
> Sent: 19 September 2002 08:09
> To: '[EMAIL PROTECTED]'
> Subject: Using GetOpt::Long
> 
> 
> I found this module was a part off the package, and tried it 
> out, it works as i want. I have some troubles though, i am 
> going to use quite a lot of sub routines in my scrip, how can 
> i define and structure so that the commandline switches will 
> actually be the subs executed?
> 
> for example i have this:
> 
> use Getopt::Long;
> 
> if (!GetOptions("reg_backup" => \$reg_backup,
>"html"  => \$html)
>){err_exit("$usage\n",0);}
> 
> if (defined ($reg_backup) ){reg_backup()}
> if (defined($html)){create_html()}
> etc..
> 
> when i execute the script it does as its told, but if i want 
> to combine the 2 subs, so that it should first run the 
> regbackup sub, (then i have the resul in an array), then it 
> should print that result in the html sub. how should i 
> structure the if statments to accomplish this?

do you want something like this?

use strict;
use English;

# Set Default values
our %opt = (
  reg_backup => 0, # Default is no reg_backup
  html   => 0, # Default is no html
);

# Allow Command Line override of defaults
GetOptions(
  \%opt,
  'reg_backup!',
  'html!',
 ) or die "GetOptions error: $OS_ERROR";

my @result;
@result = reg_backup() if $opt{reg_backup};
create_html( \@result ) if $opt{html};

you can then call your script like this:
  myscript.pl --reg_backup --html
  myscript.pl --noreg_backup --html  
  myscript.pl --reg_backup --nohtml
etc etc

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using GetOpt::Long

2002-09-19 Thread Jeff AA


> -Original Message-
> From: David Samuelsson (PAC) 
> [mailto:[EMAIL PROTECTED]] 
> Sent: 19 September 2002 08:09
> To: '[EMAIL PROTECTED]'
> Subject: Using GetOpt::Long
> 
> 
> I found this module was a part off the package, and tried it 
> out, it works as i want. I have some troubles though, i am 
> going to use quite a lot of sub routines in my scrip, how can 
> i define and structure so that the commandline switches will 
> actually be the subs executed?
> 
> for example i have this:
> 
> use Getopt::Long;
> 
> if (!GetOptions("reg_backup" => \$reg_backup,
>"html"  => \$html)
>){err_exit("$usage\n",0);}
> 
> if (defined ($reg_backup) ){reg_backup()}
> if (defined($html)){create_html()}
> etc..
> 
> when i execute the script it does as its told, but if i want 
> to combine the 2 subs, so that it should first run the 
> regbackup sub, (then i have the resul in an array), then it 
> should print that result in the html sub. how should i 
> structure the if statments to accomplish this?

do you want something like this?

use strict;
use English;

# Set Default values
our %opt = (
  reg_backup => 0, # Default is no reg_backup
  html   => 0, # Default is no html
);

# Allow Command Line override of defaults
GetOptions(
  \%opt,
  'reg_backup!',
  'html!',
 ) or die "GetOptions error: $OS_ERROR";

my @result;
@result = reg_backup() if $opt{reg_backup};
create_html( \@result ) if $opt{html};

you can then call your script like this:
  myscript.pl --reg_backup --html
  myscript.pl --noreg_backup --html  
  myscript.pl --reg_backup --nohtml
etc etc


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Using GetOpt::Long

2002-09-18 Thread David Samuelsson (PAC)

I found this module was a part off the package, and tried it out, it works as i want. 
I have some troubles though, i am going to use quite a lot of sub routines in my 
scrip, how can i define and structure so that the commandline switches will actually 
be the subs executed?

for example i have this:

use Getopt::Long;

if (!GetOptions("reg_backup" => \$reg_backup,
 "html"  => \$html)
   ){err_exit("$usage\n",0);}

if (defined ($reg_backup) ){reg_backup()}
if (defined($html)){create_html()}
etc..

when i execute the script it does as its told, but if i want to combine the 2 subs, so 
that it should first run the regbackup sub, (then i have the resul in an array), then 
it should print that result in the html sub. how should i structure the if statments 
to accomplish this?

//Dave


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




a bit over the top wraper for Getopt::Long

2002-08-30 Thread drieux


Since I had to go and clean up my old friend,
because I actually had to do it - and since
I have frumped about

did you put in the '--help|-h|-?' thing
for making sure that people have their gnu style help

I thought I should show one of several ways to do this.

http://www.wetware.com/drieux/pbl/perlTrick/CommandLine/do_get_opt_long.txt

This was derived from a form we had been using as
a sorta stock way to spin up bunches of command line
options with Getopt::Long -

http://www.wetware.com/drieux/pbl/perlTrick/CommandLine/simple_get_long.txt

I just always promised myself that when I had the time I was
gonna clean all of that up and stash it in a function that
would be easier to maintain - as I cut and pasted it around
the world... Oh if ONLY this were do-able as a 'module' thing
that one could have the full on 'just generic' - but

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Getopt::Long option prefix

2002-08-26 Thread Karl Kaufman

Hi David,

>From what I've seen, Getopt::Long default behavior is to accept either
'--opt|-opt'.   (Tested on Solaris 2.6 w/ Perl 5.005_03)

 test.pl  
#!/usr/local/bin/perl
use strict;
use diagnostics;
use Getopt::Long;
my %pagerdest = ();
Getopt::Long::Configure('default');
GetOptions(  "pagerdest=s%" => \%pagerdest );
foreach my $keyname (sort keys %pagerdest)
{
print "pagerdest $keyname = $pagerdest{$keyname}\n";
}
#

>  ./test.pl -pagerdest a=lkfd
pagerdest a = lkfd



- Original Message -
From: david
To: [EMAIL PROTECTED]
Sent: Monday, August 26, 2002 7:03 PM
Subject: Re: Having problems with AppConfig::Getopt module


Karl Kaufman wrote:

>> For example:
>>
>>   # test.pl -pagerdest [EMAIL PROTECTED]

is the above another typo? should it be:

test.pl --pagerdest [EMAIL PROTECTED]

you seem to have only one '-' in front of pagerdest?
Getopt::Long uses '--' not '-'

david


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Parameter parsing with Getopt::Long in functions

2002-06-15 Thread Robert Kasunic

Hello Paul,

On Sat, Jun 15, 2002 at 06:27:18PM +0200, Paul Johnson wrote:
> > sub test_params()
> > {
> >@ARGV=@_;
>  local @ARGV = split " ", shift;
> Hopefully you can work out what the problem was and why the fix works.

I can't believe how blind I've been. Thank you very much. I now
clearly see the problem and thanks to you the solution too.

Robert

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Parameter parsing with Getopt::Long in functions

2002-06-15 Thread drieux


On Saturday, June 15, 2002, at 09:27 , Paul Johnson wrote:

> On Sat, Jun 15, 2002 at 06:10:23PM +0200, Robert Kasunic wrote:
>> Hello,
[..]
>> sub test_params()
>> {
>>@ARGV=@_;
>
>  local @ARGV = split " ", shift;
>
>>print "ARGV: @ARGV\n";

>> }
>>
>> &test_params("-a argument_a -b -c");
>> &test_params("--opta argument_a -b -c");
>> &test_params("-b");
>> &test_params("-c -b");

H! My complements

The problem is not really with the Getopt::Long,
but with the need to be more sensitive to

a) perldoc perlsub
- cf the prototyping problem here
- note the warning if the "&" is removed

b) perldoc perldata and perldoc -f split

since what is being passed is a string, and should
be converted by any means neccesary into an array

GOOD use of the 'local' since we are dealing with a
'reserved token'

cf: http://www.wetware.com/drieux/pbl/bloopers/BadParamPassing.txt

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Parameter parsing with Getopt::Long in functions

2002-06-15 Thread drieux


On Saturday, June 15, 2002, at 09:10 , Robert Kasunic wrote:

>
> I'm trying to use Getopt::Long for parsing parameters passed to a
> function. I tried to test if that works by using the following script.
>
> ---
> #!/usr/bin/perl -w
> use strict;
> use Getopt::Long;
>
> sub test_params()
> {
>@ARGV=@_;
>print "ARGV: @ARGV\n";

that Could be the place that is causing emotional
trauma for the system - so what I offer you is
perchance a bit harry, but it creates a programme
that will allow you to screw around with IT as
the place to learn how to code this up


http://www.wetware.com/drieux/pbl/perlTrick/SafelyPlayWithGetOpt.txt


Ok, so I am lazy - I want the code to manage passing the
arguments to an external application to make sure that
it understands how to do the song and dance with Getopt::Long...

HTH

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Parameter parsing with Getopt::Long in functions

2002-06-15 Thread Paul Johnson

On Sat, Jun 15, 2002 at 06:10:23PM +0200, Robert Kasunic wrote:
> Hello,
> 
> I'm trying to use Getopt::Long for parsing parameters passed to a
> function. I tried to test if that works by using the following script.
> 
> ---
> #!/usr/bin/perl -w
> use strict;
> use Getopt::Long;
> 
> sub test_params()
> {
>@ARGV=@_;

 local @ARGV = split " ", shift;

>print "ARGV: @ARGV\n";
> 
>my $a=0;
>my $b=0;
>my $c=0;
> 
>GetOptions( "a|opta=s"   => \$a,
>"b"  => \$b,
>"c|optc" => \$c );
> 
>print "opta: $a\n";
>print "optb: $b\n";
>print "optc: $c\n\n\n";
> }
> 
> &test_params("-a argument_a -b -c");
> &test_params("--opta argument_a -b -c");
> &test_params("-b");
> &test_params("-c -b");
> ---
> 
> Unfortunately it doesn't work.

Hopefully you can work out what the problem was and why the fix works.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Parameter parsing with Getopt::Long in functions

2002-06-15 Thread Robert Kasunic

Hello,

I'm trying to use Getopt::Long for parsing parameters passed to a
function. I tried to test if that works by using the following script.

---
#!/usr/bin/perl -w
use strict;
use Getopt::Long;

sub test_params()
{
   @ARGV=@_;
   print "ARGV: @ARGV\n";

   my $a=0;
   my $b=0;
   my $c=0;

   GetOptions( "a|opta=s"   => \$a,
   "b"  => \$b,
   "c|optc" => \$c );

   print "opta: $a\n";
   print "optb: $b\n";
   print "optc: $c\n\n\n";
}

&test_params("-a argument_a -b -c");
&test_params("--opta argument_a -b -c");
&test_params("-b");
&test_params("-c -b");
---

Unfortunately it doesn't work. The first call to the function gives the
following output:

  ARGV: -a argument_a -b -c
  Unknown option: a argument_a -b -c
  opta: 0
  optb: 0
  optc: 0

As you can see the module complains about an unkown option. The dash before the
'a' is missing, so I suppose that it has something to do with the error. If the
functions is called with only one parameter then it works.

Any hints on how to get it working?

Cheers
Robert

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: getOpt::long?

2002-03-13 Thread Nikola Janceski

try 
$ perldoc Getopt
No documentation found for "Getopt".
However, try
    perldoc Getopt::Long
perldoc Getopt::Std
perldoc Getopt::Long.html
perldoc Getopt::Std.html

-Original Message-
From: Jason Larson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 11:28 AM
To: 'michael'
Cc: [EMAIL PROTECTED]
Subject: RE: getOpt::long?

answers your questions, though running perldoc -f getopt didn't return
anything for me, so you might have to check some of the other sources.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: getOpt::long?

2002-03-13 Thread Jason Larson

> -Original Message-
> From: michael [mailto:[EMAIL PROTECTED]]
> Subject: Re: getOpt::long?
> >
> > > I am a true perl newbie.
> >
> > If you continue like this you will stay one.
> >
> :-) Thanks for all the feedback. I had intended to send the 
> assignment as an
> attachment and ask about:
> 1) Configuring my win2k box so that I could use the command 
> line to run a
> perl program without having to type 'perl' before the name of 
> the program in
> order to execute it, and

All the information you should need about the AS install of Perl should be
on your start menu as: Start | Programs | ActiveState ActivePerl 5.6 |
Documentation.  To answer your specific question, you can open the html
file: file:///C:/Perl/html/faq/Windows/ActivePerl-Winfaq4.html and select
"How do I associate Perl scripts with perl?"  I'd detail the answer for you,
but it's already been done, so it'll be easier for both of us if you read
the documentation.

> 2) How to access perl documentation.

a) Start | Programs | ActiveState ActivePerl 5.6 | Documentation
b) You can also go to C:\Perl\bin, and run perldoc from there (it is a batch
file that emulates perldoc on Unix)
c) http://www.perldoc.com
d) Install cygwin

> 
> C:\>cd perl
> 
> C:\Perl>perldoc -f getopt
> 'perldoc' is not recognized as an internal or external command,
> operable program or batch file.

Need to be in C:\Perl\bin directory

> 
> C:\Perl>perl -v
> 'perl' is not recognized as an internal or external command,
> operable program or batch file.

Need to be in C:\Perl\bin directory

> 
> I have installed ActiveState Perl 5.6.1 build 631 on this 
> machine, some time
> ago, and have previously written perl scripts on it ( small ones!).
> 
> I also have this problem on my laptop.

The aforementioned answers should resolve the issue on your laptop as well.

> 
> So I installed Mandrake Linux 8.2 last night, and am even 
> able to find the
> info on the getopt module.
> 
> Now I just have to buy a supported printer so I can print it out!
> 
> Sorry to have bothered.

Understand that we are here to help.  The feedback you got was based on the
information that was sent.  It was not meant to be degrading, but you have
to look at it from our perspective.  Now that you've re-posted, I hope this
answers your questions, though running perldoc -f getopt didn't return
anything for me, so you might have to check some of the other sources.

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





Re: getOpt::long?

2002-03-13 Thread Jenda Krynicky

From:   "michael" <[EMAIL PROTECTED]>
> :-) Thanks for all the feedback. I had intended to send the assignment as an
> attachment and ask about:
> 1) Configuring my win2k box so that I could use the command line to run a
> perl program without having to type 'perl' before the name of the program in
> order to execute it, and

Add .pl and whatever other extensions you want to the PATHEXT 
system variable (Rightclick "My Computer" and select 
Properties\Advanced\Environment Variables)

You might need to set up the file extension mapping as well. 

> 2) How to access perl documentation.
> 
> C:\>cd perl
> 
> C:\Perl>perldoc -f getopt
> 'perldoc' is not recognized as an internal or external command,
> operable program or batch file.
> 
> C:\Perl>perl -v
> 'perl' is not recognized as an internal or external command,
> operable program or batch file.

The perldoc.bat and perl.exe are in c:\perl\bin. You should have 
this path in your PATH system variable.

Jenda

=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: getOpt::long?

2002-03-13 Thread michael


- Original Message -
From: "Jenda Krynicky" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 13, 2002 7:10 AM
Subject: Re: getOpt::long?


> From:   Michael <[EMAIL PROTECTED]>
>
> > I am a true perl newbie.
>
> If you continue like this you will stay one.
>
:-) Thanks for all the feedback. I had intended to send the assignment as an
attachment and ask about:
1) Configuring my win2k box so that I could use the command line to run a
perl program without having to type 'perl' before the name of the program in
order to execute it, and
2) How to access perl documentation.

C:\>cd perl

C:\Perl>perldoc -f getopt
'perldoc' is not recognized as an internal or external command,
operable program or batch file.

C:\Perl>perl -v
'perl' is not recognized as an internal or external command,
operable program or batch file.

I have installed ActiveState Perl 5.6.1 build 631 on this machine, some time
ago, and have previously written perl scripts on it ( small ones!).

I also have this problem on my laptop.

So I installed Mandrake Linux 8.2 last night, and am even able to find the
info on the getopt module.

Now I just have to buy a supported printer so I can print it out!

Sorry to have bothered.

-michael-


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: getOpt::long?

2002-03-13 Thread Jenda Krynicky

From:   Michael <[EMAIL PROTECTED]>

> I am a true perl newbie. 

If you continue like this you will stay one.

> I am supposed to:
> 
> Write a program that finds lines in an input file and copies them to an 
> output file . The program takes the following arguments:
> 
>an input file name (a mandatory argument)
>an output filename (an optional argument, set to STDOUT if omitted), 
>a starting position number that marks the beginning of the offset (an  
>optional argument, set to the beginning of the input file if omitted) 
>an ending position number that marks the end of the offset (an optional
>argument, set to the end of the input file if omitted)
> 
> If any mandatory argument is omitted or the command is followed by a help 
> switch, your program prints out a usage on the screen (Hint: use assert.pl to 
> verify the conditions).
> ...

But this is really cool. This guy's even too lazy to at least reword 
the request, he copies the whole homework assignment over here 
without changing a single word. I'm surprised he did not leave the 
name & email of his profesor at the end.

Listen Michael, we don't do homeworks here. We are here to help 
people learn Perl, to help people finish their projects, but we are 
not here to do their work for them. How do you expect to learn 
anything if someone else does everything for you?

Jenda

=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: getOpt::long?

2002-03-12 Thread Chas Owens



On Tue, 2002-03-12 at 21:50, Michael wrote:
> I am a true perl newbie. I am supposed to:
> 

> -- 
> -it does make a difference-
>-michael-
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

Okay, so what is the question?

-- 
Today is Boomtime the 72nd day of Chaos in the YOLD 3168
Hail Eris!

Missile Address: 33:48:3.521N  84:23:34.786W


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




getOpt::long?

2002-03-12 Thread Michael

I am a true perl newbie. I am supposed to:

Write a program that finds lines in an input file and copies them to an 
output file . The program takes the following arguments:

   an input file name (a mandatory argument)
   an output filename (an optional argument, set to STDOUT if omitted), 
   a starting position number that marks the beginning of the offset (an  
   optional argument, set to the beginning of the input file if omitted) 
   an ending position number that marks the end of the offset (an optional
   argument, set to the end of the input file if omitted)

If any mandatory argument is omitted or the command is followed by a help 
switch, your program prints out a usage on the screen (Hint: use assert.pl to 
verify the conditions).

For example, 
- If the user types:

 $ seeklines in Infile out Outfile starting 3 ending 10

Your program will find the 3rd line through 10th line in Infile, and copy 
them to Outfile 

- If the user types:

  $ seeklines in Infile 

Your program will copy the entire Infile to STDOUT.

- If the user types:

  $ seeklines in Infile starting 10

Your program will copy from 10th line through the last line in Infile to 
STDOUT.

- If the user types:

$ seeklines

or

  $ seeklines h

Your program will respond something like:

  $ Usage: seeklines [-in Input] [-out Output] [-starting StartOffset]
 [-ending EndOffset] 

Use one of the Getopt functions to parse the command-line arguments. For 
details on the usage of Getopt functions, type the following commands:

$ perldoc Getopt::Std
$ perldoc Getopt::Long

Take into account the following conditions:
The input file should exist.
If the output file does NOT exist, create one. If exists, append the output 
to the file. What if the end offset is smaller than the start offset number? 
What if either or both of the offset numbers are out of boundary?





-- 
-it does make a difference-
   -michael-

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Getopt::Long problem (Allegedly)

2002-01-30 Thread Briac Pilpré

On Wed, 30 Jan 2002 21:47:15 -, Angus Laycock wrote:
> --=_NextPart_000_01D4_01C1A9D7.AEC826A0
> Content-Type: text/plain;
>   charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> 
> Hi,
> 
> I wrote this today on UNIX . When I tested the script, calling it with 
> all the options (f s D P U S e q ) the "-s" option would not return the 
> value from the command line. All the other variables got populated. I 
> then change the "s:s" to "f:s" and that worked. I am trying to replace 
> some software which uses -s as an option and need to handle the options 
> the same in the PERL replacement. Is there a bug with "s:s"?
> 

By default, Getopt::Long is case insensitive. Try adding the "bundling"
and "ignore_case" options.

cf perldoc Getopt::Long (Configuring Getopt::Long)

#!/usr/bin/perl -w
use strict;
use Getopt::Long qw(GetOptions);
Getopt::Long::Configure ("bundling", "ignore_case");

my($DATABASE, $PASSWORD, $USER, $SERVER, $ERR, $SPROC, $QUERY, $TT)
=('')x8;

GetOptions(
'f:s' => \$TT,
's:s' => \$SPROC,
'D:s' => \$DATABASE,
'P:s' => \$PASSWORD,
'U:s' => \$USER,
'S:s' => \$SERVER,
'e'   => \$ERR,
'q:s' => \$QUERY
) || die "Options incorrect\n";

print <<"_EOT_";
DATABASE = $DATABASE
PASSWORD = $PASSWORD
USER = $USER
SERVER   = $SERVER
ERR  = $ERR
SPROC= $SPROC
QUERY= $QUERY
TT   = $TT
_EOT_

__END__
-- 
briac
 << dynamic .sig on strike, we apologize for the inconvenience >>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Getopt::Long problem (Allegedly)

2002-01-30 Thread Angus Laycock

Hi,

I wrote this today on UNIX . When I tested the script, calling it with all the options 
(f s D P U S e q ) the "-s" option would not return the value from the command line. 
All the other variables got populated. I then change the "s:s" to "f:s" and that 
worked. I am trying to replace some software which uses -s as an option and need to 
handle the options the same in the PERL replacement. Is there a bug with "s:s"?

use Getopt::Long;
my $DATABASE  = ""; 
my $PASSWORD  = "";
my $USER = "";
my $SERVER = "";
my $ERR  = ""; 
my $SPROC = "";
my $QUERY = "";   
my $TT  = "";
GetOptions ( 'f:s' => \$TT, 's:s' => \$SPROC, 'D:s' => \$DATABASE,'P:s' => \$PASSWORD, 
  'U:s' => \$USER, 'S:s' => \$SERVER,'e' => \$ERR,'q:s' => \$QUERY) 
  || die "Options incorrect\n";

print "DATABASE =  $DATABASE\n PASSWORD = $PASSWORD\n USER = $USER\n  SERVER = 
$SERVER\n 
 ERR = $ERR\n  SPROC = $SPROC\n  QUERY = $QUERY\n  TT = $TT\n";
exit 0;


I have just tried it at home and using "-s" and "-S" to try and replicate at home on 
ActivePerl but it puts the options in the -S variable, not in "-s"


C:\Perl\scripts>perl getopt_test1.pl -s sausage -S slow
  DATABASE =
 PASSWORD =
 USER =
 SERVER = slow
 ERR =
 SPROC =
 QUERY =

I have now changed to using getopts which works but am curious why using Getopt::Long 
doesn't like the -s option.

Help please

Thanks in  Advance

Gus





Re: GetOpt::Long - Usage question

2001-08-15 Thread Michael Fowler

On Wed, Aug 15, 2001 at 02:49:34PM -0700, pn wrote:
> #/usr/bin/perl -w
> use strict;
> 
> # Forward declarations
> 
> my $opt_help;

This is your problem right here.  Getopt::Long sets the package global
$main::opt_help, but now that you've declared the variable lexical, anytime
you access it unqualifed in your program you'll get the lexical variable. 

The solution is to either declare it global, with our or use vars, or pass
in a variable to GetOptions.  E.g.


our $opt_help;
GetOptions('help|h');

OR

use vars qw($opt_help);
GetOptions('help|h');

OR

GetOptions('help|h' => \$opt_help);

OR (my preference)

GetOptions(\%opts, 'help|h'); # now available as $opts{'help'}


Some further commentary is below.


> sub GetCmdLine;
> 
> # Begin of Main Body
> 
> &GetCmdLine();
> 
> # End of Main Body
> 
> ######
>  Sub GetCmdLine   
> ##
> 
> sub GetCmdLine {
> 
> use Getopt::Long;

It's generally better to place use lines near the beginning of the file;
that's, conceptually, when they get executed, regardless of their position
in the code, and it provides an easy way for someone to determine the
dependencies your code has.


> $Getopt::Long::ignorecase;
> $Getopt::Long::autoabbrev;

I don't know what you intend to accomplish with these.  You're simply
mentioning the variables, you aren't assigning any values to them.

 
> 
> &GetOptions("help|h");
> 
> # Print the value of $opt_help
>print "The value of \$opt_help is : ",
> $opt_help, "\n";
> 
> if (defined($opt_help) && ($opt_help ==1)) {

It's easier to test simply for truth:

  if ($opt_help) {


>   print "\n\nUsage: $0 [options] \n";
>   print "  [optins]:\n";
>   print "\t\t-h Prints this help message
> header.\n";
> 
>  }
> }


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




GetOpt::Long - Usage question

2001-08-15 Thread pn

Hi,

I am unable to get the following inherited code, using
Getopt::Long, to work.

It is my understanding that Perl will automatically
create a $opt_help variable ( for a -help command line
option). However, when I try to print it's value, it
returns a null value. In addition, the "help" mesage
is never printed.

Here is the output of the program, when I run it:


%perl gtopt.pl -help
The value of $opt_help is : 


Any help and pointers on what might be wrong would be
greatly appreciated.

Thanks

PN


-- Source Code --
#/usr/bin/perl -w
use strict;

# Forward declarations

my $opt_help;
sub GetCmdLine;

# Begin of Main Body

&GetCmdLine();

# End of Main Body

##
 Sub GetCmdLine   
##

sub GetCmdLine {

use Getopt::Long;
$Getopt::Long::ignorecase;
$Getopt::Long::autoabbrev;


&GetOptions("help|h");

# Print the value of $opt_help
   print "The value of \$opt_help is : ",
$opt_help, "\n";

if (defined($opt_help) && ($opt_help ==1)) {

  print "\n\nUsage: $0 [options] \n";
  print "  [optins]:\n";
  print "\t\t-h Prints this help message
header.\n";

 }
}


__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: can't able to understand this behaviour of Getopt::Long

2001-08-03 Thread Michael Fowler

On Fri, Aug 03, 2001 at 04:05:33PM +0530, Rajanikanth Dandamudi wrote:
> -
> #!/usr/local/bin/perl
> use Getopt::Long;
> 
> my $filename;
> print "Before : ARGV = @ARGV\n";
> $ret = GetOptions('abc=s' =>\$filename);
> print "Return value = $ret  ";
> print "filename = $filename\n";
> print "After : ARGV = @ARGV\n";
> -
> 
> How I expect this code to behave is to match the command line switch
> -abc. But it is matching all the swithces -a , -ab , and -abc. Can
> someone help me in understanding this. When I ran this program the
> following are the results:

This is Getopt::Long's abbreviation handling; if the switch specified is a
unique abbreviation of one of the switches in GetOptions argument list, then
it acts as if the full switch was specified.  See the section "Case and
abbreviations" in perldoc Getopt::Long.  If you want to turn this feature
off specify 'no_auto_abbrev' as an argument in a call to
Getopt::Long::Configure.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




can't able to understand this behaviour of Getopt::Long

2001-08-03 Thread Rajanikanth Dandamudi

Hello,

   I am not able to understand the following behaviour of perl
Getopt::Long. Here is the snippet of code that I am not able to
understand:

Start of code
-
#!/usr/local/bin/perl
use Getopt::Long;

my $filename;
print "Before : ARGV = @ARGV\n";
$ret = GetOptions('abc=s' =>\$filename);
print "Return value = $ret  ";
print "filename = $filename\n";
print "After : ARGV = @ARGV\n";
-

How I expect this code to behave is to match the command line switch
-abc. But it is matching all the swithces -a , -ab , and -abc. Can
someone help me in understanding this. When I ran this program the
following are the results:

1. Command Line Invocation:  Getopt_Example_9.pl -a path
Output from the above code:
Before : ARGV = -a path
Return value = 1  filename = path
After : ARGV =

2. Command Line Invocation:  Getopt_Example_9.pl -ab path
Output from the above code:
Before : ARGV = -ab path
Return value = 1  filename = path
After : ARGV =

3. Command Line Invocation:  Getopt_Example_9.pl -abc path
Output from the above code:
Before : ARGV = -abc path
Return value = 1  filename = path
After : ARGV =

4. Command Line Invocation:  Getopt_Example_9.pl -ac path
Before : ARGV = -ac path
Unknown option: ac
Return value =   filename =
After : ARGV = path


For Your Information:
--
perl -V on my machine gives:
--

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:

  Platform:
osname=solaris, osvers=2.6, archname=sun4-solaris
uname='sunos linsparc89 5.6 generic_105181-21 sun4u sparc
sunw,ultra-5_10 '
config_args=''
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define
use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
  Compiler:
cc='gcc', optimize='-O', gccversion=2.95 19990728 (release)
cppflags='-fno-strict-aliasing -I/usr/local/include
-I/opt/local/include'
ccflags ='-fno-strict-aliasing -I/usr/local/include
-I/opt/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
ld='gcc -shared', ldflags =' -L/usr/local/lib '
libpth=/usr/local/lib /lib /usr/lib
libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt -lsec
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-E'
cccdlflags='-fPIC', lddlflags='-W,l-E -G -L/usr/local/lib
-R/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: USE_LARGE_FILES
  Built under solaris
  Compiled at Dec 14 2000 17:41:50
  @INC:
/usr/local/lib/perl5/5.6.0/sun4-solaris
/usr/local/lib/perl5/5.6.0
/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris
/usr/local/lib/perl5/site_perl/5.6.0
/usr/local/lib/perl5/site_perl



Thanks and Regards,
D.Rajanikanth



Re: is there a module ala getopt::long that will ... as well as command-line completion

2001-07-30 Thread Paul Johnson

On Mon, Jul 30, 2001 at 10:36:50AM -0700, Matt Lyon wrote:
> here's one for the group... is there a module ala getopt::long that will do
> the arg-getting as well as command-line completion with a predefined
> list/hash/etc... of keywords?

Command line completion is done by a shell rather than an application.
A good one will do programmable completion.  I suggest zsh.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




is there a module ala getopt::long that will ... as well as command-line completion

2001-07-30 Thread Matt Lyon

here's one for the group... is there a module ala getopt::long that will do
the arg-getting as well as command-line completion with a predefined
list/hash/etc... of keywords?

-mL
-- Life would be so much easier if its source code was well-commented.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Getopt::Long

2001-07-21 Thread iain truskett

* Bicknell, Frank ([EMAIL PROTECTED]) [21 Jul 2001 08:12]:

[...]
> Using Getopt::Long, it's possible to watch for negated options:
> -nostuff ... and it's possible to alias options "stuff|such" allows
> -stuff to be the same as -such.
[...]

> $ stuff -nosuch 
> Using Perl Version 5.00404
> Unknown option: nosuch
> Use of uninitialized value at stuff line 6.
> Stuff: <>
> $ 

> Anyone seen this before?

(a) You really should be using --nosuch rather than -nosuch.
Getopt::Long is just being smart and noting that there aren't any short
opts. 

(b) It works fine with perl 5.6 and Getopt::Long 2.25 (do the following
to determine what version you have:)

perl -MGetopt::Long -l -e'print $Getopt::Long::VERSION'

(c) You are doing the right thing.

Doing some research yields:

<http://search.cpan.org/doc/JV/Getopt-Long-2.25/CHANGES>

# Changes in version 2.22
# ---
# 
# * Fixes a bug in the combination of aliases and negation.
# 
#   Old:  "foo|bar!" allowed negation on foo, but not on bar.
#   New:  "foo|bar!" allows negation on foo and bar.
# 
#   Caveat: "foo|f!", with bundling, issues the warning that negation on
#   a short option is ignored. To obtain the desired behaviour, use
# 
# "foo!" => \$opt_foo, "f" => \$opt_foo
#   or
# "foo|f" => \$opt_foo, "nofoo" => sub { $opt_foo = 0 }
# 
#   Remember that this is _only_ required when bundling is in effect.


So it was a bug, and is now fixed. You may want to upgrade your Perl
(the newer Getopt::Long is standard in 5.6.1) or just your Getopt::Long
(using CPAN; 2.24 seems to only need Perl 5.4 or later).

So, all you need is version 2.22 or later (current 2.25).


cheers,
-- 
iain.  <http://eh.org/~koschei/>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Getopt::Long

2001-07-21 Thread Bicknell, Frank

I'm not sure if this is the right forum, but here goes (I'm a beginner
at posting questions to the list?)

Using Getopt::Long, it's possible to watch for negated options:
-nostuff
... and it's possible to alias options "stuff|such" allows -stuff to be
the same as -such.

So this little sample program:

$ cat stuff
#!/usr/local/bin/perl -w
use Getopt::Long;

print "Using Perl Version $]\n";
GetOptions (\%opt, "stuff|such!");
print "Stuff: <$opt{stuff}>\n";
$ 

Should allow one to say something like:

stuff -stuff
stuff -nostuff
stuff -such
stuff -nosuch

But look what happens:

$ stuff -stuff
Using Perl Version 5.00404
Stuff: <1>
$ stuff -such 
Using Perl Version 5.00404
Stuff: <1>
$ stuff -nostuff
Using Perl Version 5.00404
Stuff: <0>
$ stuff -nosuch 
Using Perl Version 5.00404
Unknown option: nosuch
Use of uninitialized value at stuff line 6.
Stuff: <>
$ 

Anyone seen this before?
---
Frank Bicknell, Sysadmin
Cisco Systems, Inc.
(919) 392-3798


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]