gokhan has asked for the wisdom of the Perl Monks concerning the following question:
hello, I have a problem with the parameter passing mechanism among 2 subroutines. my code is as follows.
I have 2 subroutines. the first one takes 2 parameters from command line:
* text file name containing file list
* file format
then it reads the given file, and fetches individual file names (with full path).
then it passes a file path and format to second subroutine called test_format. but these parameters becomes "unreadable" from the array object containing parameters, when I try to convert this array to an hash object (args2hash). because when I print the array object, it gives this output.
"/abc/def/xyz.dat format dat"
Actually it should be like this:
"input /abc/def/xyz.dat format dat"
The "input" keyword is missing.
What should I do?
sub test_filelist_format { my $obj = shift; my $args = Parser::args2hash (@_); my $input = $args->{'input'}; my $format = $args->{'format'}; if (!$input || !$format) { die("input file or format missing!\n"); } ## if not list readable, return -1 if ( $obj->is_readable(file=>$input) < 0 ) {return -1} ... my $formatstatus = test_format ("input" => $line, "format" => $for +mat); ... } sub test_format { my $obj = shift; my $args = Parser::args2hash (@_); my $input = $args->{'input'}; my $format = $args->{'format'}; my $gzip = $args->{'gzip'}; my $columns = $args->{'columns'}; if (!$input || !$format) { die("input file or format missing!\n"); } if ( $obj->is_readable(file=>$input) < 0 ) {return -1}; ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parameter passing problem
by kcott (Archbishop) on Jul 02, 2013 at 15:38 UTC | |
by gokhan (Initiate) on Jul 03, 2013 at 13:03 UTC | |
by gokhan (Initiate) on Jul 03, 2013 at 09:20 UTC | |
by gokhan (Initiate) on Jul 03, 2013 at 12:55 UTC | |
by toolic (Bishop) on Jul 03, 2013 at 12:58 UTC | |
|
Re: parameter passing problem
by Loops (Curate) on Jul 02, 2013 at 15:01 UTC | |
|
Re: parameter passing problem (in mystery code)
by Anonymous Monk on Jul 02, 2013 at 14:58 UTC |