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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
I am loosing value of my argument

 

First page Previous page 1 2 3 Next page Last page  View All


digioleg54
User

Jul 19, 2016, 1:18 PM

Post #1 of 65 (16329 views)
I am loosing value of my argument Can't Post

I have Perl script menu.pl. One of the argument I put from command line of menu is queue = 3. I checked it.
Then menu calls function function.pl
In this function args->{queue} = 1. I cannot understand why. I don't do anything with it.
In menu it is args_100{queue}. In function I put args->{queue}.
Where is my mistake?


FishMonger
Veteran / Moderator

Jul 19, 2016, 2:27 PM

Post #2 of 65 (16327 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

It's not possible to answer your question based on that limited and confusing info.

You need to post your code and exactly how you execute it. You also need to post any/all errors and warnings it produces and explain how the output differs from what you expect.


(This post was edited by FishMonger on Jul 19, 2016, 2:28 PM)


digioleg54
User

Jul 19, 2016, 2:32 PM

Post #3 of 65 (16324 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

The code is 1000 lines.


digioleg54
User

Jul 19, 2016, 2:39 PM

Post #4 of 65 (16321 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

The first is working menu. We put different values, date, port, queue and so on. Then we call the second script. Script starts with:
my $args{};
and then when I print args->{queue}, instead 3 a get 1.


FishMonger
Veteran / Moderator

Jul 19, 2016, 2:42 PM

Post #5 of 65 (16318 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

Without seeing your code, it's impossible for anyone to say what's wrong and how to fix it.

Write a short but complete test script which demonstrates the problem.


digioleg54
User

Jul 19, 2016, 2:50 PM

Post #6 of 65 (16316 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

*** Running : g:\invacct\perl\scripts\pfi_general_ledger_check.pl -port 10001 -e
nd_date 6/23/2016 -env PROD -nav -use_pos -basis GAAP -dir \\nynas1\nynds4\vol2\
DATA\INVACCT\Fund_Recs_PFI -journals -journals_load -queue 3


#! usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
use MOA::CLSUtils;
use MOA::PamReport;
use MOA::PamJobsPFI;
use MOA::Users;
use Data::Dumper;



my $args={};


sub run_job{

print STDOUT "$args->{queue}\n"

}

as you can see first line queue = 3. In sub $args->{queue} =1, but must be 3


FishMonger
Veteran / Moderator

Jul 19, 2016, 2:54 PM

Post #7 of 65 (16313 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

You've got to be joking!

That incomplete code doesn't even begin to demonstrate the problem.


digioleg54
User

Jul 19, 2016, 2:58 PM

Post #8 of 65 (16310 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

The program g:\\invacct\\perl\\scripts\\pfi_general_ledger_check.pl last argument is 3.
It starts running and at the beginning instead 3 I print 1


digioleg54
User

Jul 19, 2016, 3:09 PM

Post #9 of 65 (16307 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

Can I ask you in a different way.
my $que = pop(ARGV); it gives 3.
How can I put $que into $args->{queue}?


FishMonger
Veteran / Moderator

Jul 19, 2016, 5:58 PM

Post #10 of 65 (16296 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post


In Reply To
Can I ask you in a different way.
my $que = pop(ARGV); it gives 3.
How can I put $que into $args->{queue}?


2 options:

Code
$args->{queue} = $que;

or

Code
$args->{queue} = \$que;


Those 2 statements have slightly different effects/results.

The first one copies the current value of $que and the 2nd one creates a reference to the $que var. If you use the 2nd example, if $que is altered after that assignment, then so too will the value of $args->{queue} change since it's a reference to the $que var.


(This post was edited by FishMonger on Jul 19, 2016, 6:02 PM)


FishMonger
Veteran / Moderator

Jul 20, 2016, 2:20 PM

Post #11 of 65 (16271 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

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


Quote
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.

Code
#!/usr/bin/perl 

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

my $args = {};
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'
) 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.
http://search.cpan.org/~jv/Getopt-Long-2.49.1/lib/Getopt/Long.pm#Documentation_and_help_texts


Code
C:\test>Perl-1.pl -end_date now -port 3 -app 
Unknown option: app
Error in processing args


Code
C:\test>Perl-1.pl -end_date now -port 3 
$VAR1 = {
'port' => '3',
'end_date' => 'now'
};



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


FishMonger
Veteran / Moderator

Jul 20, 2016, 5:43 PM

Post #12 of 65 (16265 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

I've gone back over this thread and your PM's to me and as I've pointed out several times none of the code you've posted demonstrates your problem and it's clear that you have a minimal level of perl knowledge and probably won't be able to troubleshoot this on your own.

So, I will make this offer; if you provide me (via PM) a zip archive of your scripts and modules, I will spend a reasonable amount of time looking them over to see if I can find where your code is modifying that hash value. I'm assuming your code does lots of things that I can't reasonably duplicate so I may or may not be able to find the cause of the problem.


(This post was edited by FishMonger on Jul 20, 2016, 5:51 PM)


FishMonger
Veteran / Moderator

Jul 21, 2016, 8:58 AM

Post #13 of 65 (16246 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

Copying the PM messages to this thread.

digioleg54
Below is my command and print dumper. I don't understand, why

Quote
g:\invacct\perl\scripts\pfi_general_ledger_check.pl -port 10001 -e
nd_date 6/23/2016 -env PROD -nav -use_pos -basis GAAP -dir \\nynas1\nynds4\vol2\
DATA\INVACCT\Fund_Recs_PFI -journals -journals_load -queue 3


Code
$VAR1 = { 
'journals' => 1,
'end_date' => '6/23/2016',
'nav' => 1,
'journals_load' => 1,
'queue' => 1,
'dir' => '\\\\nynas1\\nynds4\\vol2\\DATA\\INVACCT\\Fund_Recs_PFI',
'basis' => 'GAAP',
'use_pos' => 1,
'env' => 'PROD',
'port' => '10001'
};


fishmonger

Quote
I don't know why I missed this earlier, maybe it was due to the poor formatting of that code, but the "queue" option is defined as a Boolean flag instead of an an integer. That is why it's being assigned a 1 instead of the 3.


digioleg54
how can I define it as integer?

fishmonger
'queue=i'


digioleg54
User

Jul 21, 2016, 9:36 AM

Post #14 of 65 (16242 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

when I put "queue=I" in Getopts, it show the message:

Option queue requires an argument

-port and -end_date are required parameters

-dev Use dev dir
-port PAM portfolio number
-start_date start_date of pam reports
-end_date end_date of pam reports. Date Format
is mm/dd/yyyy
-pam use reports( hard coded names ) run o
ut of pam to user hard coded directory
-xrun recycle auto run pam jobs
-tb run run trial balance only


digioleg54
User

Jul 21, 2016, 9:45 AM

Post #15 of 65 (16240 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

I use Perl for windows


FishMonger
Veteran / Moderator

Jul 21, 2016, 9:58 AM

Post #16 of 65 (16239 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post


In Reply To
when I put "queue=I" in Getopts, it show the message:

Option queue requires an argument


You used the wrong character. You should use a lowercase i not an uppercase I.


(This post was edited by FishMonger on Jul 21, 2016, 10:00 AM)


digioleg54
User

Jul 21, 2016, 10:01 AM

Post #17 of 65 (16236 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

I use lower case 'queue=i'


FishMonger
Veteran / Moderator

Jul 21, 2016, 10:10 AM

Post #18 of 65 (16234 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

C:\test>type Perl-1.pl

Code
#!/usr/bin/perl 

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

my $args = {};
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=i'
) 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";
}



Code
C:\test>Perl-1.pl -port 10001 -end_date 6/23/2016 -env PROD -nav -use_pos -basis GAAP -dir \\nynas1\nynds4\vol2\DATA\INV ACCT\Fund_Recs_PFI -journals -journals_load -queue 3 
$VAR1 = {
'queue' => 3,
'basis' => 'GAAP',
'end_date' => '6/23/2016',
'env' => 'PROD',
'dir' => '\\\\nynas1\\nynds4\\vol2\\DATA\\INVACCT\\Fund_Recs_PFI',
'journals_load' => 1,
'journals' => 1,
'port' => '10001',
'nav' => 1,
'use_pos' => 1
};



digioleg54
User

Jul 21, 2016, 10:12 AM

Post #19 of 65 (16232 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

Did you do it for Windows 7?


FishMonger
Veteran / Moderator

Jul 21, 2016, 10:15 AM

Post #20 of 65 (16229 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

yes


Quote
C:\test>ver

Microsoft Windows [Version 6.1.7601]



(This post was edited by FishMonger on Jul 21, 2016, 10:16 AM)


digioleg54
User

Jul 21, 2016, 10:19 AM

Post #21 of 65 (16225 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

The problem is that I have menu. The menu ask questions, I put my answers as args. I catch $job_queue=pop(@ARGV); 16th element is queue and it is =3, or any number I put. But if I put GetOpts 'dueue=i', program crushes


FishMonger
Veteran / Moderator

Jul 21, 2016, 10:23 AM

Post #22 of 65 (16222 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

What version of perl are you using and what version of Getopt::Long?


Quote
I catch $job_queue=pop(@ARGV);

That's a bad way to handle these types of options/arguments.

What is the output of dumping @ARGV prior to using pop or shift?

Code
print Dumper \@ARGV;



(This post was edited by FishMonger on Jul 21, 2016, 10:26 AM)


digioleg54
User

Jul 21, 2016, 10:27 AM

Post #23 of 65 (16219 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

perl v5.18.4 for Win32
Getopts was installed in 2013
long.pm
package Getopt::Long;

use 5.004;

use strict;

use vars qw($VERSION);
$VERSION = 2.42;

last modify Tue Oct 1 08:25:52 2013


FishMonger
Veteran / Moderator

Jul 21, 2016, 10:30 AM

Post #24 of 65 (16216 views)
Re: [digioleg54] I am loosing value of my argument [In reply to] Can't Post

Upgrade the module and dump @ARGV to verify its contents.


digioleg54
User

Jul 21, 2016, 10:34 AM

Post #25 of 65 (16215 views)
Re: [FishMonger] I am loosing value of my argument [In reply to] Can't Post

$VAR1 = [
'-port',
'10001',
'-end_date',
'6/23/2016',
'-env',
'PROD',
'-nav',
'-use_pos',
'-basis',
'GAAP',
'-dir',
'\\\\nynas1\\nynds4\\vol2\\DATA\\INVACCT\\Fund_Recs_PFI',
'-journals',
'-journals_load',
'-queue',
'5'
];


I put queue = 5 now

First page Previous page 1 2 3 Next page Last page  View All
 
 


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

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