Here's my sub that exhibits the problem:

sub merge_dat {
    my($new_file_name, 
        $existing_file_name, 
        $output_file_name, 
        $start_elaphrs, 
        $end_elaphrs, 
        $time_adjust,
        $existing_file_orig_name,
        $period_file,
        $indent,
        $verbose,
        $discard_dups) = (@_);

Here's the calling code:

merge_dat($file_to_process, $aggregate_dat_file, $temp_file_b, undef, undef, 0, undef, undef, $indent."   ", $verbose, $discard_dups, 0);

Turns out $discard_dups is always undef. $verbose always comes through just fine. Why does that argument and any following always come out as undef?

What would be a good work-around solution?

2

There are 2 best solutions below

0
ikegami On

There is no limit. It's very easy to prove there isn't a ten element limit.

$ perl -M5.010 -E'sub f { say for @_ } f(1..11);'
1
2
3
4
5
6
7
8
9
10
11

If $discard_dups is undef, either @_ has fewer than 11 elements, or the value of the 11th scalar provided is undef.

3
Polar Bear On

Your question does not provide any minimal code sample to demonstrate the problem.

The source of the problem is hidden in your code.

use strict;
use warnings;
use feature 'say';

use Data::Dumper;

my @array;

@array = map { int(rand(500)) } 0..100;

merge_dat(@array);

sub merge_dat {
    my(@args) = @_;
    my $count = 0;
    say $count++ . " $_" for @args;
}

It does not make much sense to pass big array as an argument, it would take a lot of resources to create a copy and wastes CPU cycles.

In such situation it is better to utilize array reference or hash reference.

use strict;
use warnings;
use feature 'say';

use Data::Dumper;

my $data;

$data->{new_fname}      = '/some/file/location1';
$data->{existing_fname} = '/some/file/location2';
$data->{out_fname}      = '/some/file/location3';
$data->{start}          = '1003';
$data->{end}            = '30013';
$data->{time_adj}       = '0:14:18.8';
$data->{orig_fname}     = '/some/file/location0';
$data->{time_period}    = '0:35';
$data->{indent}         = 8;
$data->{verbose}        = 0;
$data->{dup_discard}    = 1;

merge_dat($data);

sub merge_dat {
    my $param = shift;

    say Dumper($param);
    say '=' x 45;
    say 'Out filename: ' . $param->{out_fname};
}

Output

$VAR1 = {
          'dup_discard' => 1,
          'out_fname' => '/some/file/location3',
          'existing_fname' => '/some/file/location2',
          'new_fname' => '/some/file/location1',
          'time_adj' => '0:14:18.8',
          'time_period' => '0:35',
          'indent' => 8,
          'orig_fname' => '/some/file/location0',
          'end' => '30013',
          'start' => '1003',
          'verbose' => 0
        };

=============================================
Out filename: /some/file/location3