CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [digioleg54] I am loosing value of my argument: Edit Log

Veteran / Moderator

Jul 20, 2016, 2:20 PM

Views: 31000
Re: [digioleg54] I am loosing value of my argument

Moving PM communication over to the original thread where it belongs.

I use it in a different program. But after that statement print args->{queue} = 1, but supposed to be different. And I don't know why.the line is:

if (!GetOptions($args,"help","dir=s","dev","port=s","end_date=s","pam","xrun","tb","nav","use_pos","basis=s","env=s","final","dev","journals","journals_load","close","no_glck","calc_nav","recycle","check_mzpx","performance","queue") || !$args->{end_date} || !$args->{port} )
usage(" -port and -end_date are required parameters");
I print exactly after the line and get 1.Something is wrong.

That is difficult to read, and difficult to maintain. At the very least you should add vertical whitespace i.e., put each option on a separate line.

Here's a cleaned up version.


use strict;
use warnings FATAL => 'all';
use Getopt::Long;
use Data::Dumper;

my $args = {};
) or usage('Error in processing args');

if (! exists $args->{end_date} || ! exists $args->{port}) {
usage('-port and -end_date are required parameters');

print Dumper $args;

sub usage {
my $msg = shift || 'Error';
die "$msg\n";

Instead of the usage sub, a better approach would be to add the Pod::Usage module. An example of its usage is in the Getopt::Long documentation.

C:\test> -end_date now -port 3 -app 
Unknown option: app
Error in processing args

C:\test> -end_date now -port 3 
$VAR1 = {
'port' => '3',
'end_date' => 'now'

(This post was edited by FishMonger on Jul 20, 2016, 2:24 PM)

Edit Log:
Post edited by FishMonger (Veteran) on Jul 20, 2016, 2:24 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives