In Perl, you can copy a set (implemented using arrays or other data structures) by creating a new array and assigning the elements of the original set to it.
In this example,
@numbers
containing some integer elements.@copiedNumbers
and assign the elements of @numbers
to it.@copiedNumbers
contains a copy of all elements from @numbers
.my @numbers = (1, 2, 3, 4, 5);
my @copiedNumbers = @numbers;
print "Copied Numbers: @copiedNumbers\n";
Copied Numbers: 1 2 3 4 5
In this example,
@fruits
containing some string elements.@copiedFruits
and assign the elements of @fruits
to it.@copiedFruits
contains a copy of all elements from @fruits
.my @fruits = ("Apple", "Banana", "Cherry", "Date");
my @copiedFruits = @fruits;
print "Copied Fruits: @copiedFruits\n";
Copied Fruits: Apple Banana Cherry Date
In this tutorial, we learned How to Copy a Set in Perl language with well detailed examples.