Some general observations on the code:
-
if (ref($replacement) eq 'ARRAY' && length $replacement > 1) { ... }
length always operates on a string or stringized expression. A stringized reference looks something like "ARRAY(0x123abc)", so the expression length $replacement > 1 will always be true if $replacement is a reference.
Win8 Strawberry 5.8.9.5 (32) Fri 08/05/2022 17:16:08
C:\@Work\Perl\monks
>perl
use strict;
use warnings;
my $arrayref = [ ]; # ref. to zero length array
print "$arrayref \n";
print "length non-zero \n" if length $arrayref > 1;
^Z
ARRAY(0x613824)
length non-zero
The number of elements of an array is found by evaluating the array in scalar context
(update: see Context and subsequent topics in perldata)
or, in newer Perls (5.12+), by the keys built-in evaluated in scalar context (check your documentation).
Win8 Strawberry 5.30.3.1 (64) Fri 08/05/2022 17:39:54
C:\@Work\Perl\monks
>perl
use strict;
use warnings;
my $arrayref = [ 9, 8, ]; # ref. to NON-zero length array
printf "number of elements of referenced array: %d \n", scalar @$
+arrayref;
printf "number of elements of referenced array: %d \n", 0 + @$
+arrayref;
printf "number of elements of referenced array: %d \n", scalar keys @$
+arrayref;
print "number of elements > 1 \n" if @$arrayref > 1;
print "number of elements > 1 \n" if keys @$arrayref > 1;
^Z
number of elements of referenced array: 2
number of elements of referenced array: 2
number of elements of referenced array: 2
number of elements > 1
number of elements > 1
(Update: Just to be clear, a proper re-statement of the condition expression would be
if (ref($replacement) eq 'ARRAY' && @$replacement > 1) { ... }
The > numeric comparison imposes scalar context.)
-
if ($choice eq 'y' || 'Y') { ... }
This condition evaluates as "if $choice is 'y' or if the string 'Y' is true", i.e., it's always true because 'Y' is always true. See What is true and false in Perl?
An effective case-insensitive conditional test would be
if (lc($choice) eq 'y') { ... }
Give a man a fish: <%-{-{-{-<