Perl Language Reading a file's content into a variable Slurping a file into an array variable


Example

open(my $fh, '<', "/some/path") or die $!;
my @ary = <$fh>;

When evaluated in list context, the diamond operator returns a list consisting of all the lines in the file (in this case, assigning the result to an array supplies list context). The line terminator is retained, and can be removed by chomping:

chomp(@ary); #removes line terminators from all the array elements.