-1

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?

eggwad
  • 1
  • 2
  • 3
    No, there's no limits like that. (1) Check your syntax. (For example, if `$verbose` is in fact `@verbose` then that would take all remaining arguments and `$discard_dups` will stay `undef`) (2) Show how you call the function. Best, show us a complete (short) program that shows the problem – zdim Oct 14 '21 at 00:20
  • 2
    Please follow [How to create a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) guideline. – Polar Bear Oct 14 '21 at 01:39
  • There we go -- the `$discard_dups` _that is passed to the function_ must be `undef` itself, so when it is assigned (to `$discard_dups` in the function) then that one is `undef`. (And then you pass yet one more argument than what the function uses, a `0`. It's just hard to keep track of everything with so many arguments; I'd suggest reworking that...) – zdim Oct 14 '21 at 06:32
  • I have also used a literal 1 instead of $discard_dups and it comes through as undef as well. – eggwad Oct 14 '21 at 16:06

2 Answers2

1

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.

ikegami
  • 367,544
  • 15
  • 269
  • 518
-1

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
Polar Bear
  • 6,762
  • 1
  • 5
  • 12
  • 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);``` – eggwad Oct 14 '21 at 03:21
  • I only can see that the function is called with 12 parameters, no clue what is stored in the variables. It is not obvious what `$indent." "` is -- what is stored in `$indent` variable? May be you wanted to pass `" " x $indent` instead. – Polar Bear Oct 14 '21 at 03:43
  • Please follow [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) otherwise it is not possible to identify your problem. Inspect content of all variables directly before call for the function. – Polar Bear Oct 14 '21 at 03:44