First of all, congratulations for the good sense to use strict and warnings.
Let's walk through your script's run:
- $test is declared and defined with the string of true.
- $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.
- 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
- The first conditional detects that $test contains true, so we move into the second conditional.
- 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.
- 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;