in reply to rectangularizing input to become array
Hello Aldebaran,
Just a couple of points in haukex’s excellent answer that I would like to emphasise:
almost certainly doesn’t do what you think it does. The documentation for Path::Tiny::slurp says that it “Reads file contents into a scalar.” So after that line of code is executed, the array @lines contains a single entry, identical to the string previously assigned to $guts. To get an array of lines, you need to split the string, either on newlines as haukex showed:my @lines = $path_to_file->slurp;
or using the special multiline pattern documented in split:my $guts = $path_to_file->slurp; my @lines = split /\n/, $guts;
The latter preserves newlines in the input data, including blank lines at the end of the input file; the former does not.my $guts = $path_to_file->slurp; my @lines = split /^/, $guts;
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: rectangularizing input to become array
by Aldebaran (Curate) on Feb 28, 2019 at 19:58 UTC |