1

The documentation of File::Modified says:

my $d = File::Modified->new(files=>['Import.cfg','Export.cfg']);

The files parameter looks to me as being an array.

Why can I not directly hand over an array?

my $d = File::Modified->new(files=>@array);

This creates a runtime error.

2
  • Does this answer your question? Passing array to subroutine Perl Commented Aug 30, 2023 at 12:58
  • files=>@array would results in files=>'Import.cfg', 'Export.cfg'=>undef Commented Aug 30, 2023 at 13:39

1 Answer 1

3

The files parameter is not an array; it is a reference to an array.
The File::Modified POD says:

Files, which takes an array reference to the filenames to watch.

This is why you can not simply pass an array variable like that.

The square brackets create a reference to an array, which is different from an array.

As the perlref document shows, one way to take a reference to an array is to use the backslash:

my $d = File::Modified->new(files => \@array);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.