in reply to Can't use an undefined value as an ARRAY reference at ./test.pl line 14.

First of all, congratulations for the good sense to use strict and warnings.

Let's walk through your script's run:

  1. $test is declared and defined with the string of true.
  2. $lib is declared but not defined (meaning, no value is assigned to initialize it. When a variable is not defined, in Perl, loosely speaking, it contains undef.
  3. GetOptions is invoked, and detects that the test flag appeared on the command line with a value of "true". The libFile flag was NOT provided on the command line, so no value is assigned to $lib
  4. The first conditional detects that $test contains true, so we move into the second conditional.
  5. The second conditional attempts to dereference $lib. That is, it attempts to access the array reference contained in $lib. But wait, $lib doesn't contain an array reference. It doesn't contain anything aside from undef.
  6. Since Perl cannot dereference an entity that does not contain a reference, it throws an error and exits, unable to comply with the request. It simply will not pull a rabbit out of a hat (particularly when using strict, as you are correctly doing).

Where you may be getting confused is over the concept of Perl's autovivification. This does work:

use strict; use warnings; my $foo; push @$foo, 'bar';

But this does not work:

use strict; use warnings; my $foo; my @bar = @$foo;

Dave